New MetaTrader 5 Platform build 2005: Economic Calendar, MQL5 applications as services


The MetaTrader 5 platform update will be released on February 21, 2019. The new version features the following changes:

  1. Terminal: Completely revised built-in Economic Calendar.

    The Economic Calendar is our proprietary solution. Therein you will find over 600 financial news and indicators related to the 13 largest global economies: USA, European Union, Japan, UK, Canada, Australia, China among others. Relevant data is collected from open sources in real time.

    The new version features updated contents and advanced event filters: by time, priority, currencies and countries.

    The calendar data can now be accessed from MQL5 programs. Please see below for details.

  2. Terminal: Added new type of MQL5 applications — Services. This new type enables the creation of custom price feeds for the terminal, i.e. to implement price delivery from external systems in real time, just like it is implemented on brokers' trade servers.

    Unlike Expert Advisors, indicators and scripts, services are not linked to a specific chart. Such applications run in the background and are launched automatically when the terminal is started (unless such an app was forcibly stopped).

    Services can be managed from a new section within the Navigator window:

    How to create services
    To create a service template, use the corresponding MQL5 Wizard option. Services have one OnStart entry point, similar to scripts. At this point, you can implement an endless data receiving and handling cycle using network functions.

    How to launch services
    To run multiple Expert Advisor or indicator copies with different parameters, you should launch them on different charts. In this case different program instances are created, which then operate independently. Services are not linked to charts, therefore a special mechanism has been implemented for the creation of service instances.

    Select a service from the Navigator and click "Add service" in its context menu. This will open a standard MQL5 program dialog, in which you can enable/disable trading and access to signal settings, as well as set various parameters.

    A service instance can be launched and stopped using the appropriate instance menu. To manage all instances, use the service menu.

  3. Terminal: A learning program has been added.

    The new feature will help beginners in learning how to interact with the platform. We have added over 100 interactive tips concerning the main platform features.

    • Tips are seamlessly displayed as a progress bar on the toolbar and thus they do not distract the user.
    • Tips only appear for the actions which you have never performed in the platform.
    • All tips include interactive links, by which you can navigate to the relevant interface elements. For example, a trading dialog or a menu with the desired program can be launched straight from the tip.

    The filled area of the progress bar will increase whenever you perform appropriate actions and continue training.

  4. Terminal: The trading account history can be presented as positions. The platform collects data on deals related to the position (opening, volume increase, partial or full closing) and groups the information into a single record. Thus you can access position details: open and close time, volume, price and result. This efficient presentation form is now available in history reports exported to files.

  5. Terminal: Added new API enabling request of MetaTrader 5 terminal data through applications
  6. Terminal: Optimized Close By dialog used for closing a position by an opposite one. Now, the dialog is not slowed down even if you have a large number of open positions.
  7. Terminal: Fixed synthetic symbol calculation errors, due to which data could be occasionally skipped.
  8. Terminal: When a custom symbol is deleted, files storing its tick and bar history are also deleted. This avoids the accumulation of unused data on the hard disk.
  9. Terminal: Fixed display of search results on High DPI screens.
  10. MQL5: Implemented access to economic calendar data from MQL5 programs.

    New functions

    CalendarCountryById — gets country description by identifier.
    bool CalendarCountryById(
       const long           country_id,    // country ID
       MqlCalendarCountry&  country        // country description
    CalendarEventById — gets event description by identifier.
    bool CalendarEventById(
       const long           event_id,      // event ID
       MqlCalendarEvent&    event          // event description
    CalendarValueById — gets event value description by identifier.
    bool CalendarValueById(
       const long           value_id,      // value ID
       MqlCalendarValue&    value          // value description
    CalendarEventByCountry — gets the array of available events for the country.
    bool CalendarEventByCountry(
       string               country_code,  // country code
       MqlCalendarEvent&    events[]       // array of events
    CalendarEventByCurrency — gets the array of available events for the affected currency.
    bool CalendarEventByCurrency(
       string               currency,      // currency
       MqlCalendarEvent&    events[]       // array of events
    CalendarValueHistoryByEvent — gets the array of values for the specified time period, by event identifier.
    bool CalendarValueHistoryByEvent(
       ulong                event_id,      // event ID
       MqlCalendarValue&    values[],      // array of values
       datetime             datetime_from, // period beginning date
       datetime             datetime_to=0  // period end date
    CalendarValueHistory — gets the array of values for the specified time period for all events, filtered by country and/or currency.
    bool CalendarValueHistory(
       MqlCalendarValue&    values[],          // array of values
       datetime             datetime_from,     // beginning of period
       datetime             datetime_to=0,     // end of period
       string               country_code=NULL, // country code
       string               currency=NULL      // currency
    CalendarValueLastByEvent — gets an array of last event values by identifier. This function enables the request of the values which have appeared since the previous request. The in/out parameter "change_id" is additionally used for this operation.

    Every time the calendar database changes, the "change_id" property (the last change identifier) is updated. During data request, you specify "change_id" and the terminal returns events which appeared after that time, as well as the current "change_id" value, which can be used for the next request. During the first function call, specify the zero "change_id": the function will not return any events, but will return the current "change_id" for further requests.
    bool CalendarValueHistory(
       ulong                event_id,          // event ID
       ulong&               change_id,         // last calendar change ID
       MqlCalendarValue&    values[]           // array of values
    CalendarValueLast — gets the array of last values for all events, filtered by country and/or currency. This function enables the request of the values which have appeared since the previous request. Similarly to CalendarValueLastByEvent, the "change_id" property is used for the request.
    bool CalendarValueHistory(
       ulong                event_id,          // event ID
       ulong&               change_id,         // last calendar change ID
       MqlCalendarValue&    values[],          // array of values
       string               country_code=NULL, // country code
       string currency=NULL                    // currency

    New structures

    MqlCalendarCountry — country description.
    struct MqlCalendarCountry
       ulong             id;                        // country ID in ISO 3166-1
       string            name;                      // text name of the country
       string            code;                      // code name of the country in ISO 3166-1 alpha-2
       string            currency;                  // country currency code
       string            currency_symbol;           // country currency symbol/sign
       string            url_name;                  // country name used in URL on
    MqlCalendarEvent — event description.
    struct MqlCalendarEvent
       ulong                          id;           // event ID
       ENUM_CALENDAR_EVENT_TYPE       type;         // event type
       ENUM_CALENDAR_EVENT_SECTOR     sector;       // sector to which the event belongs
       ENUM_CALENDAR_EVENT_FREQUENCY  frequency;    // event release frequency
       ENUM_CALENDAR_EVENT_TIMEMODE   time_mode;    // event release time mode
       ulong                          country_id;   // country ID
       ENUM_CALENDAR_EVENT_UNIT       unit;         // unit for the event values
       ENUM_CALENDAR_EVENT_IMPORTANCE importance;   // event importance
       ENUM_CALENDAR_EVENT_MULTIPLIER multiplier;   // event importance multiplier
       uint                           digits;       // number of decimal places in the event value
       string                         source_url;   // source URL
       string                         event_code;   // event code
       string                         name;         // text name of the event in the terminal language
    MqlCalendarValue — event value description.
    struct MqlCalendarValue
       ulong             id;                        // value ID
       ulong             event_id;                  // event ID
       datetime          time;                      // event date and time
       datetime          period;                    // period, for which the event is published
       int               revision;                  // published indicator revision in relation to the reported period
       long              actual_value;              // current event value
       long              prev_value;                // previous event value
       long              revised_prev_value;        // revised previous event value
       long              forecast_value;            // forecast event value
       ENUM_CALENDAR_EVENT_IMPACRT impact_type;     // potential impact on the currency rate

    New enumerations

       CALENDAR_FREQUENCY_NONE            =0,   // not used
       CALENDAR_FREQUENCY_WEEK            =1,   // weekly
       CALENDAR_FREQUENCY_MONTH           =2,   // monthly
       CALENDAR_FREQUENCY_QUARTER         =3,   // quarterly
       CALENDAR_FREQUENCY_YEAR            =4,   // yearly
       CALENDAR_FREQUENCY_DAY             =5,   // daily
       CALENDAR_TYPE_EVENT                =0,   // event (meeting, speech, etc.)
       CALENDAR_TYPE_INDICATOR            =1,   // indicator
       CALENDAR_TYPE_HOLIDAY              =2,   // holiday
       CALENDAR_SECTOR_NONE               =0,   // no
       CALENDAR_SECTOR_MARKET             =1,   // market
       CALENDAR_SECTOR_GDP                =2,   // GDP
       CALENDAR_SECTOR_JOBS               =3,   // jobs
       CALENDAR_SECTOR_PRICES             =4,   // prices
       CALENDAR_SECTOR_MONEY              =5,   // money
       CALENDAR_SECTOR_TRADE              =6,   // trade
       CALENDAR_SECTOR_GOVERNMENT         =7,   // government
       CALENDAR_SECTOR_BUSINESS           =8,   // business
       CALENDAR_SECTOR_CONSUMER           =9,   // consumer
       CALENDAR_SECTOR_HOUSING            =10,  // housing
       CALENDAR_SECTOR_TAXES              =11,  // taxes
       CALENDAR_SECTOR_HOLIDAYS           =12,  // holidays
       CALENDAR_IMPORTANCE_NONE           =0,   // no
       CALENDAR_IMPORTANCE_LOW            =1,   // low
       CALENDAR_IMPORTANCE_MODERATE       =2,   // moderate
       CALENDAR_IMPORTANCE_HIGH           =3,   // high
       CALENDAR_UNIT_NONE                 =0,   // no
       CALENDAR_UNIT_PERCENT              =1,   // percent
       CALENDAR_UNIT_CURRENCY             =2,   // national currency
       CALENDAR_UNIT_HOUR                 =3,   // number of hours
       CALENDAR_UNIT_JOB                  =4,   // number of jobs
       CALENDAR_UNIT_RIG                  =5,   // number of rigs
       CALENDAR_UNIT_USD                  =6,   // US dollar
       CALENDAR_UNIT_PEOPLE               =7,   // number of people
       CALENDAR_UNIT_MORTGAGE             =8,   // number of mortgages
       CALENDAR_UNIT_VOTE                 =9,   // number of votes
       CALENDAR_UNIT_BARREL               =10,  // number of barrels
       CALENDAR_UNIT_CUBICFEET            =11,  // volume in cubic feet
       CALENDAR_UNIT_POSITION             =12,  // number of job positions
       CALENDAR_UNIT_BUILDING             =13   // number of buildings
       CALENDAR_MULTIPLIER_NONE           =0,   // no    
       CALENDAR_MULTIPLIER_THOUSANDS      =1,   // thousands
       CALENDAR_MULTIPLIER_MILLIONS       =2,   // millions
       CALENDAR_MULTIPLIER_BILLIONS       =3,   // billions
       CALENDAR_MULTIPLIER_TRILLIONS      =4,   // trillions
       CALENDAR_IMPACT_NA                 =0,   // not available
       CALENDAR_IMPACT_POSITIVE           =1,   // positive
       CALENDAR_IMPACT_NEGATIVE           =2,   // negative
       CALENDAR_TIMEMODE_DATETIME         =0,   // the source publishes the exact time
       CALENDAR_TIMEMODE_DATE             =1,   // the event takes the whole day
       CALENDAR_TIMEMODE_NOTIME           =2,   // the source does not publish the event time
       CALENDAR_TIMEMODE_TENTATIVE        =3,   // the source provides only date, but does not publish the exact time in advance, exact time is added when event occurs

    New error codes

    ERR_CALENDAR_MORE_DATA             =5400,   // the array is too small for the whole result (values which fit in the array were passed)
    ERR_CALENDAR_TIMEOUT               =5401,   // timed out waiting for a response to the calendar data request
    ERR_CALENDAR_NO_DATA               =5402,   // data not found

  11. MQL5: Fixes and operation speed improvements related to tick and bar history.
  12. MQL5: Fixes and significant operation speed improvements related to tick and bars history modification functions of custom trading symbols, CustomTicks* and CustomRates*.
  13. MQL5: New data conversion functions.

    CharArrayToStruct copies a uchar array to a POD structure.
    bool  CharArrayToStruct(
       void&         struct_object,    // structure
       const uchar&  char_array[],     // array
       uint          start_pos=0       // starting position in the array
    StructToCharArray copies a POD structure to a uchar array.
    bool  StructToCharArray(
       const void&  struct_object,     // structure
       uchar&       char_array[],      // array
       uint         start_pos=0        // starting position in the array

  14. Added MathSwap function for changing byte order in ushort, uint and ulong values.
    ushort MathSwap(ushort value);
    uint   MathSwap(uint   value);
    ulong  MathSwap(ulong  value);

  15. MQL5: Added network functions for creating TCP connections to remote hosts via system sockets:

    • SocketCreate creates a socket with specified flags and returns its handle
    • SocketClose closes the socket
    • SocketConnect connects to the server, with timeout control
    • SocketIsConnected checks if the socket is currently connected
    • SocketIsReadable gets the number of bytes which can be read from the socket
    • SocketIsWritable checks if data writing to this socket is possible at the current time
    • SocketTimeouts sets data receiving and sending timeouts for the system socket object
    • SocketRead reads data from a socket
    • SocketSend writes data to a socket
    • SocketTlsHandshake initiates a secure TLS (SSL) connection with the specified host using the TLS Handshake protocol
    • SocketTlsCertificate receives information concerning the certificate used for secure network connection
    • SocketTlsRead reads data from a secure TLS connection
    • SocketTlsReadAvailable reads all available data from a secure TLS connection
    • SocketTlsSend sends data using a secure TLS connection

    The address of the host, to which connection using network functions is established, must be explicitly added to the list of allowed addresses in terminal settings.

    New error codes have been added for operations with network functions:

    • ERR_NETSOCKET_INVALIDHANDLE (5270): invalid socket handle passed to the function
    • ERR_NETSOCKET_TOO_MANY_OPENED (5271): too many sockets open (maximum 128)
    • ERR_NETSOCKET_CANNOT_CONNECT (5272): error while connecting to remote host
    • ERR_NETSOCKET_IO_ERROR (5273): error while sending/receiving data from the socket
    • ERR_NETSOCKET_HANDSHAKE_FAILED (5274): secure connection establishment error (TLS Handshake)
    • ERR_NETSOCKET_NO_CERTIFICATE (5275) — no data about certificate used for secure connection

  16. MQL5: Added new functions for string operations:

    StringReserve reserves for a string the memory buffer of the specified size.
    bool  StringReserve(
       string&        string_var,          // string
       uint           new_capacity         // buffer size for the string
    StringSetLength sets the specified string length in characters.
    bool  StringSetLength(
       string&        string_var,          // string
       uint           new_length           // new string length

  17. MQL5: Added new function for array operations:

    ArrayRemove removes from an array the specified number of elements starting with the specified index.
    bool  ArrayRemove(
       void&         array[],              // array of any type
       uint          start,                // the index to start removal
       uint          count=WHOLE_ARRAY     // number of elements
    ArrayInsert inserts to a receiver array the specified number of elements from the source array, starting with the specified index.
    bool  ArrayInsert(
       void&         dst_array[],          // receiver array
       const void&   src_array[],          // source array
       uint          dst_start,            // index in the receiver array where to insert
       uint          src_start=0,          // index in the source array to start copying
       uint          count=WHOLE_ARRAY     // number of inserted elements
    ArrayReverse reverses in an array the specified number of elements starting with the specified index.
    bool  ArrayReverse(
       void&         array[],              // array of any type
       uint          start=0,              // index to start reversing
       uint          count=WHOLE_ARRAY     // number of elements

  18. MQL5: New "uint count" parameter has been added in functions CustomRatesUpdate, CustomRatesReplace, CustomTicksAdd and CustomTicksReplace. It allows specification of the number of elements of the passed array, which will be used for these functions. The WHOLE_ARRAY value is used for the parameter by default. It means that the whole array will be utilized.
  19. MQL5: Added CustomBookAdd function to pass the status of the Depth of Market for a custom symbol. The function allows broadcasting the Depth of Market as if the prices arrive from a broker's server.
    int  CustomBookAdd(
       const string        symbol,            // symbol name
       const MqlBookInfo&  books[]            // an array with the DOM elements descriptions
       uint                count=WHOLE_ARRAY  // number of elements to be used
  20. MQL5: Added CustomSymbolCreate function overloading. This allows the creation of a custom trading symbol based on an existing one. After creation, any symbol property can be edited using corresponding functions.
    bool  CustomSymbolCreate(
       const string        symbol_name,       // custom symbol name
       const string        symbol_path="",    // name of the group in which the symbol will be created
       const string        symbol_origin=NULL // name of the symbol based on which the custom symbol will be created
    The name of the symbol, from which the properties of for the custom symbol should be copied, is specified in the "symbol_origin" parameter.

  21. The StringToTime function converting the string with date/time to a datetime value has been updated. Now it supports the following date formats:

    • [hh:mi]
    • [hh:mi:ss]
    • yyyymmdd [hh:mi:ss]
    • yyyymmdd [hhmiss]
    • yyyy/mm/dd [hh:mi:ss]
    • yyyy-mm-dd [hh:mi:ss]

  22. MQL5: New TERMINAL_VPS property in the ENUM_TERMINAL_INFO_INTEGER enumeration; it shows that the terminal is running on the MetaTrader Virtual Hosting server (MetaTrader VPS). If an application is running on a hosting server, you can disable all its visual functions, since the virtual server does not have a graphical user interface.
  23. MQL5: New SYMBOL_EXIST property in the ENUM_SYMBOL_INFO_INTEGER enumeration, means that the symbol under this name exists.
  24. MQL5: Fixed typing when using template function pre-declarations.
  25. MQL5: Added re-initialization of indicators when changing a trading account.
  26. MQL5: Optimized StringSplit function.
  27. MQL5: Fixed errors in the standard library operation.
  28. Tester: Added TesterStop function — routine early shutdown of an Expert Advisor on a test agent. Now you can forcibly stop testing after reaching the specified number of losing trades, a preset drawdown level or any other criterion.

    Testing completed using this function is considered successful. After the function call, the trading history obtained during testing and all trade statistics are passed to the terminal.

  29. Tester: Disabled ability to test and optimize Expert Advisors through MQL5 Cloud Network in the real tick mode. This mode can only be used on local agents and local network farms.
  30. Tester: Improved work with indicators during visual testing. Now the price chart and indicator lines are drawn synchronously, even for the maximum visualization speed.
  31. Tester: Optimized and significantly accelerated testing and optimization.
  32. Tester: Fixed debugging of indicators on historical data. Now the OnInit and OnDeinit indicator functions can be properly debugged.
  33. Tester: Implemented faster access to historical data when testing multicurrency Expert Advisors.
  34. Tester: Fixed occasional freezing of the visual tester during debugging on historical data.
  35. Tester: Implemented faster start of optimization passes when processing a task package by an agent.
  36. Tester: Changed policy of distributing task packages to testing agents. The package size has been increased and thus resource consumption on network operations has been significantly reduced.
  37. Tester: Changed behavior of options enabling the use of local, network and cloud agents. Now, when you switch off the options, the agents complete processing of received tasks, while no more new tasks are given to them. In earlier versions, the behavior was similar to the "Disable" command, which immediately stopped agent operation.

  38. MetaEditor: Added support for non-ANSI characters in the debugger. Now, the expressions are properly displayed even if the variable name is specified in Cyrillic.
  39. MetaEditor: Fixed display of search results on High DPI screens.
  40. Added user interface translation into Croatian.
  41. Documentation has been updated.
The update will be available through the LiveUpdate system.
Sergey Golubev  

We all can update Metatrader 5 to build 2005 - 

How to update: open demo account with MetaQuotes-Demo, and use MT5 menu (Help - Check Desktop Updates - Latest Release Version) - 


That's potentially great news, thanks for this much longed for feature!

However, the Economic Calendar as accessible by MQL5 seems to be still empty, or why else does...

MqlCalendarValue value[];

ulong changeID;



...only return 0-values for datetime 1970 01 01?

Any solutions?

By the way I would suggest to please update the new related online documentation with tables which event ID (e.g. "840040003" in my example code) stands for which event name etc., so that the users don't have to do this detective work everytime themselves.

Many thanks!

What's new in MetaTrader 5
What's new in MetaTrader 5
MetaTrader 5 Platform build 2005: Economic Calendar, MQL5 applications as services and R language API Terminal Completely revised built-in Economic Calendar. The Economic Calendar is our proprietary solution. Therein you will find over 600 financial news and indicators related to the 13 largest global economies: USA, European Union, Japan...

Thanks for the new Calendar functions! -- I had a few questions and comments...

CalendarValueLastByEvent and CalendarValueLast function descriptions

I found the following descriptions a little confusing:- 'Get the array of event values by its ID since the Calendar database status with a specified change_id.' and 'Get the array of values for all events with the ability to sort by country and/or currency since the calendar database status with a specified change_id.' respectively.

My understanding is these functions return the latest value of an event or events when the change_ID change from specified one. However I find the wording 'since the calendar database status with a specified change_id.' unclear. It would help to clarify the process for how the calendar is updated and specify what conditions need to be met for the the change_ID to change? -- In particular are updates to the calendar batched and if so by what criteria are they batched and is there one change_id per batch?

Speed of update

I'd be interested to know how quickly (qualitatively) the calendar is updated after the source site is updated. -- does your system check the source sites for updates every x milliseconds or something? - if so how frequently? -- Can I expect Reuters terminal speed or more Tradingview/dailyfx/fxstreet etc type speed? -- I've found that there is often considerable (well a number of seconds) between the former and the latter...


I don't seem to be able to access the calendar when backtesting using strategy tester. For instance I tried running code based on examples in the reference doc to print country IDs and Event IDs. It works as expected when I drop it in an EA or Scrip and run live in the terminal but CalendarCountries returned nothing when I ran it the strategy tester (by the way the example code assumes CalendarCountries returns 0 when no countryID are found by I got a -1)

Is there a way to use the calendar when backtesting?


You mention this new datafeed service being used for alternative pricing data feeds. Let say I wanted to compliment the calendar updates with data release info from other sources, perhaps to cross reference the data or get faster access, could one use this new datafeed functionality to achieve this?

Thanks again.
Andreas Hoogendoorn  

I think there is a typo in the calendar impact enumeration

IMPACRT should that be IMPACT ?

   CALENDAR_IMPACT_NA                 =0,   // not available
   CALENDAR_IMPACT_POSITIVE           =1,   // positive
   CALENDAR_IMPACT_NEGATIVE           =2,   // negative

Alain Verleyen  
Andre Hoogendoorn:

I think there is a typo in the calendar impact enumeration

IMPACRT should that be IMPACT ?

Already fixed. Wait next release.
Chris Sthojan  



I don't seem to be able to access the calendar when backtesting using strategy tester. For instance I tried running code based on examples in the reference doc to print country IDs and Event IDs. It works as expected when I drop it in an EA or Scrip and run live in the terminal but CalendarCountries returned nothing when I ran it the strategy tester (by the way the example code assumes CalendarCountries returns 0 when no countryID are found by I got a -1)

Is there a way to use the calendar when backtesting?


Hello, I'm also interested in this. Any updates? Would be great if there was a way to backtest, even if it involves exporting the calendar from the terminal or from a script.

As for feedback, most functions are straightforward enough to use, and a welcomed addition. I did struggle a bit with CalendarValueHistory(), because it seems to me like it sets the time (datetime) member of the MqlCalendarValue struct to GMT time, while in the terminal's calendar they show up as the broker's time. Considering news come from the broker's server (from my understanding), it would be nice to have consistency and not have to manipulate TimeCurrent() to fit a time range.

Hello I'm new here just show me how to do