Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

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 Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

AllinOneAlerts – Amibroker Alerts Module for Amibroker Users

AllinOneAlerts is one of the most important and most requested modules to bring all sorts of alerts with no extra coding efforts. Now even...
Rajandran R
5 min read

How to improve your Amibroker Algo Trading Execution Speed

When comes to Automated Trading speed of execution plays a dominant role in executing at better prices. Here I would like to list three...
Rajandran R
1 min read

Introduction to QuantZilla 2.0

QuantZilla is a 75+ hours of immersive coding mentor-ship program on designing trading systems, converting trading ideas into indicators and trading strategies, automating the...
Rajandran R
4 min read

Leave a Reply

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