Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Displaying Weather Dashboard in your Amibroker

1 min read

Thought of brining weather data into Amibroker. Googled for free weather api data. OpenWeathermap came to my notice. Using Openweathermap one can get weather data for any location on the globe immediately.

Sample Weather Output

{"coord":{"lon":77.6,"lat":12.98},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":
{"temp":294.15,"feels_like":297.36,"temp_min":294.15,"temp_max":294.15,"pressure":1012,"humidity":100},"visibility":6000,"wind":
{"speed":1.39,"deg":288},"clouds":{"all":75},"dt":1602971629,"sys":
{"type":1,"id":9208,"country":"IN","sunrise":1602981608,"sunset":1603024139},"timezone":19800,"id":1277333,"name":"Bengaluru","cod":200}

Amibroker AFL Code to get the Weather Dashboard

Code requires Amibroker 6.17 as some of the new AFL functions like InternetClose( handle ) , InternetOpenURL( “url” ) , InternetReadString( handle ) – which is essecial to read from internet resource/http api is available from v6.17 or higher version.

// Coder - Rajandran R
// Founder - Marketcalls.in & Co-Founder - Algomojo.com
// Algomojo Provides Free API + Free Trading Bridge for API Based Automated Trading
// Creation Date : 15th Oct 2020
// Weather Display Dashboard




_SECTION_BEGIN("Weather Display Dashboard");
Version(6.17);  //Code is Compatible with 6.17 and Higher
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorDefault, styleNoTitle | styleCandle | GetPriceStyle() ); 

city = ParamStr("City","Bangalore");

ih = InternetOpenURL( "http://api.openweathermap.org/data/2.5/weather?q="+city+"&appid=1f082c296a4b6013f8976bdf820147c2" );

if( ih )
{
     while( ( str = InternetReadString( ih ) ) != "" )
     {
         //printf( "%s", str );
          for( item = -1; ( sym = StrExtract( str, item,'{' )) != ""; item-- )
	 {
	 
	 if(item == -4)
	 {
	 //printf( "%s", sym );
	 
	 for( jitem = -1; ( temp = StrExtract( sym, jitem,',' )) != ""; jitem-- )
	 {
	 printf( "\n%s", temp );
	 if(Strfind(temp,"temp"))
	 {
     temp1 = StrExtract(temp,1,':');
     temp1 = StrTrim(temp1,"\"");
    //_TRACE("\nTemperature : "+NumToStr(StrToNum(temp1)-273.15) +" Degree Celsious");
	 }
	 
	 if(Strfind(temp,"feels_like"))
	 {
     fl = StrExtract(temp,1,':');
     fl = StrTrim(fl,"\"");
    //_TRACE("\nFeels Like : "+NumToStr(StrToNum(fl)-273.15)+" Degree Celsious");
	 }
	 
	 
	 if(Strfind(temp,"humidity"))
	 {
     hm = StrExtract(temp,1,':');
     hm = StrTrim(hm,"\"");
     hm = StrTrim(hm,"}");
    //_TRACE("\nHumidity : "+hm);
	 }
	 
	  if(Strfind(temp,"pressure"))
	 {
     pr = StrExtract(temp,1,':');
     pr = StrTrim(pr,"\"");

    //_TRACE("\nPressure : "+pr);
	 }
	 
	 
	 }
	 
     
     }
	 }

     }
     InternetClose( ih );
      
}

//Display Weather Dashboard

GfxSetBkMode( 0 );
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetTextColor( colorWhite );


GfxSelectPen( colorGreen, 2 ); 
GfxSelectSolidBrush( colorgreen ); 
GfxRectangle( 10, 20, 250, 180 );

GfxTextOut( "City : "+city,23,23); 
GfxTextOut( "Temperature : " +NumToStr(StrToNum(temp1)-273.15) +" °C" ,23,48); 
GfxTextOut( "Feels Like : " +NumToStr(StrToNum(fl)-273.15) +" °C",23,73);
GfxTextOut( "Humidity : " + hm+"%",23,98); 
GfxTextOut( "Pressure : " + pr+"hPa",23,123);
   
    

_SECTION_END();

Now I nevermind to short Nifty Futures if Bangalore weather is crossing 30 degree Celsius!

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Pivot Reversal Strategy – Tradingview Pinescript to Amibroker AFL…

Pivot Reversal Strategy is a popular in-built strategy in Tradingview Platform. Here I had attempted to convert the pinescript v5 to Amibroker AFL Code....
Rajandran R
3 min read

Interactive Brokers – Smart Order Chart Trading Module using…

The IB Controller is an interface designed to facilitate automatic trading with AmiBroker and Interactive Brokers (IB) TWS (Trader Workstation). It serves as a...
Rajandran R
8 min read

Introducing OpenAlgo V1.0: The Ultimate Open-Source Algorithmic Trading Framework…

OpenAlgo V1.0 is an open-source algorithmic trading platform to automate your trading strategies using Amibroker, Tradingview, Metatrader, Python etc. Designed with the modern trader...
Rajandran R
2 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More