Download MetaTrader 5
New robots and indicators every day!

Displaying a News Calendar

23 November 2007, 16:08
Slobodov Gleb
6 400


This article contains the description of writing a simple and convenient indicator displaying in a working area the main economic events from external Internet resources. The indicator's operation looks like this:

Here is a list of requirements for the indicator:
  • The indicator should independently (without a user's help) download a necessary file of the events calendar for the current week.
  • The indicator should display all events (both passed and future) from this file in the form of vertical lines with news headlines.
  • The indicator should trace the events' update on the external resource.
After we have specified the task, we can analyze some technical details.

Technical Part

Let us use the website as an external resource. The convenience of this resource is that it enables to download a calendar with .csv extension, so we avoid difficulties of working with html files. Here is a link of news for the current week:

Now let us dwell on the process of downloading the file from the Internet. This can be done using a well-known program GetRight. It can be downloaded at: or from the list of attachments to this article.

After you have downloaded the program, set up GetRight for downloading files into a necessary directory. It is the \files\html\ directory in the folder of your trading terminal. To do this, press F8 and change the writing in the field as described below:

Writing the Indicator

Now having answered some questions, we can start writing the indicator.

extern string HtmlAdress = "";
extern string GetrightAdress = "c:\progra~1\getright\getright.exe";
#include <Time.mqh>
#import "kernel32.dll"
int WinExec(string NameEx, int dwFlags);

There are only two external variables: the address of the external resource (actually, you do not have to change this parameter) and the address of the GetRight program (if you have downloaded the program into another directory, I recommend to change the initial value in the indicator, in order not to change the value of the variable constantly at the indicator start). To start the file GetRight.exe we will have to use the function WinExec that can be imported from the Kernel32.dll library. The library Time.mqh contains functions for working with GMT.

void DownloadCalendar()
 Print("Downloading "+HtmlAdress+" to experts\files\html\Calendar.csv");
 WinExec(GetrightAdress+" /URL:"+HtmlAdress+" /FILE:Calendar.csv /W /O",0);

As you can see, due to the usage of the GetRight program the function of downloading the file from the external resource looks like very simple.The parameter /W denotes that the process will not be returned into the program unless the file downloading is completed. The parameter /O denotes that if there is a file with the same name, it will be overwritten. Remember, if you have changed the settings of GetRight correctly, the calendar will be downloaded into \files\html\. And here are two additional functions:

datetime PerviousMonday(datetime d)
 datetime res = d - (TimeDayOfWeek(d)-1)*24*60*60;
datetime ToDate(string stDate,string stTime)  
 string WeekDay = StringSubstr(stDate,0,3);
 int WeekPlus = 0;
 if (WeekDay=="Mon") WeekPlus=0;
 if (WeekDay=="Tue") WeekPlus=1;
 if (WeekDay=="Wed") WeekPlus=2;
 if (WeekDay=="Thu") WeekPlus=3;
 if (WeekDay=="Fri") WeekPlus=4;
 if (WeekDay=="Sat") WeekPlus=5;
 if (WeekDay=="Sun") WeekPlus=-1;
 datetime Res = PerviousMonday(GetTimeGMT())+WeekPlus*24*60*60;
 datetime Tm = StrToTime(stTime);
 Res=Res+TimeHour(Tm )*60*60+TimeMinute(Tm )*60+TimeSeconds(Tm )
 if (StringFind(stTime,"PM")>=0)  
 return (Res);

The function PerviousMonday() returns the starting date of the current week. The function ToDate() transfers the date and the time from the calendar format into datatime.

void GrabNews()  
 int file = FileOpen("\Html\Calendar.csv",FILE_READ|FILE_CSV,',');
 if (file==-1||FileSize(file)==0)
 int i=0;
 while (!FileIsEnding(file))
 string stDate="";
 while (!FileIsEnding(file)&&stDate=="")
 stDate = FileReadString(file);
 string stTime = FileReadString(file);
 string stTimeZone = FileReadString(file);
 string stCurrency = FileReadString(file);
 string stDescription = FileReadString(file);
 string stImportance = FileReadString(file);
 string stActual = FileReadString(file);
 string stForecast = FileReadString(file);
 string stPrevious = FileReadString(file);
 datetime Date = ToDate(stDate,stTime);
 color c=Green;
 if (stImportance=="Low") c = Yellow;
 if (stImportance=="Medium") c = Orange;
 if (stImportance=="High") c = Red;
 ObjectCreate("CalendarText"+i, OBJ_TEXT, 0, Date, Close[0]);
 ObjectSet("CalendarText"+i, OBJPROP_COLOR, c);  
 ObjectSetText("CalendarText"+i, stDate + " : "+ stDescription, 8);  
 ObjectSet("CalendarText"+i, OBJPROP_ANGLE, 90);  
 ObjectCreate("CalendarLine"+i, OBJ_VLINE, 0, Date, Close[0]);
 ObjectSet("CalendarLine"+i, OBJPROP_COLOR, c);  
 ObjectSet("CalendarLine"+i, OBJPROP_STYLE, STYLE_DOT);  
 ObjectSet("CalendarLine"+i, OBJPROP_BACK, true);  
 ObjectSetText("CalendarLine"+i, stDescription, 8);  
 Max = i;
 if (file!=-1)

The main procedure GrabNews() opens the downloaded file \Html\Calendar. csv, reads all event parameters and creates two objects for each news: a vertical line and a text. The event calendar is updated every 15 minute:

int start()
   int    counted_bars=IndicatorCounted();
   if (TimeCurrent()>LastTimeDownloading+15*60)
       LastTimeDownloading = TimeCurrent();
       int file=-1;
       while (file==-1)
         file = FileOpen("\Html\Calendar.csv",FILE_READ|FILE_CSV,',');


The article explained how to display an event calendar from an external resource onto a working area in the form of vertical lines. The indicator was intentionally written without any excessive parameters like filtering news according to their relevance or the correspondence of an event and the symbol of the current window.

P.S. I would like to point at an error in the calendar operation Please note that sometimes events in the file .csv from the address are not identical with the page This may happen to news released from 00:00 till 01:00 (GMT). In the file .csv such news are indicated 12 hours later.

Also please note, that the indicator uses external dll (kernell32.dll), so do not forget to enable the corresponding parameter in the indicator settings.

The file CalendarArticle.mq4 should be stored in the folder \experts\indicators. Time.mq4 should be stored in expers\library, Time.mqh - in experts\include.

Translated from Russian by MetaQuotes Software Corp.
Original article:

Attached files | (4763.33 KB)
Time.mq4 (2.03 KB)
Time.mqh (0.73 KB)
Last comments | Go to discussion (29)
MQL4 Comments
MQL4 Comments | 21 Apr 2011 at 16:17
Placed files in correct places and got "Time.mqh" - cannot open the program file
MQL4 Comments
MQL4 Comments | 21 Apr 2011 at 16:39
-... it is really retarded that one needs a separate program to first download web data in order for indicator to read it.. how much more cumbersome a platform can get...!!?? MT4/5 are designed for brokers and paid by brokers, it's not build for programmers or traders and this becomes painfully obvious when one get's to know MT4/5 more closely....
Dominic Gilbert
Dominic Gilbert | 10 Oct 2013 at 10:43
Man I really wish this was still working :(
Swaraj Thakur
Swaraj Thakur | 30 Apr 2014 at 19:28
I think the thread is dead, but I believe someone implemented it in an EA.. I am foward testing it at the moment.. Will update once I get any significant results..