Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

Economic Calendar CSV - script for MetaTrader 5

Views:
2667
Rating:
(6)
Published:
2024.10.22 16:31
Updated:
2024.11.22 20:23
\MQL5\Include\MQL5Book\
AutoPtr.mqh (1.86 KB) view
Defines.mqh (0.71 KB) view
IS.mqh (0.98 KB) view
StringUtils.mqh (1.91 KB) view
TimeServerDST.mqh (15.68 KB) view
CalendarCache.mqh (28.54 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This is an extended version of the script CalendarForDates.mq5 presented in the algotrading book.

Input variables allows you to specify a country code, a currenty code, and a time range to filter required records. If the inputs are left empty, a complete calendar can be requested (if the calendar is requested first time after the terminal started, it can take a while for downloading its base or even time out and produce no results - then please run the script once again).

As a result, you'll get a CSV-file with calendar records with most important fields (not all fields are exported - feel free to adjust the source code according to your needs).

Optionally, one can input a *.cal-file (archived copy of the calendar for specific time) created by the indicator CalendarMonitorCached.mq5 also introduced in the book, which is now obsolete in favor of its extended version CalendarMonitorCachedTZ.mq5 (recommended and required for the new feature, described next).

MetaTrader's Economic Calendar in CSV


The most interesting feature: the script demonstrates the usage of TimeServerDST.mqh for adjusting historical events' timestamps in accordance with the server's time zone changes in past, which are persistently reflected in candles' timestamps. This mode is enabled by settings the input FixCachedTimesBySymbolHistory to true.

Saving events into CSV-files with and without the correction makes it easy to compare effects of time correction on the history.

For proper usage of this feature, it's recommended to run the script on XAUUSD or EURUSD H1 charts. When used programmatically, these symbols should be passed to TimeServerDST's functions.

The same approach is used in the indicator CalendarMonitorCachedTZ.mq5 for exporting time-corrected calendar events into archived cal-files, ready for loading from inside the tester, that ensures accurate backtests and optimizations of news robots.

Range of dates in which the time corrections are performed is limited to the maximal number of bars on the chart for timeframe H1. This is the specificity of the empirical method used inside TimeServerDST.mqh.

Let us consider a specific event type, preferably with a large impact on the market, such as a release of US Nonfarm Payrolls (NFP).

On a European server with DST schedule (MQ Demo) it occurs at 14:30 in winter and at 15:30 in summer. On the screenshot below you can see side by side 2 versions of complete calendar history exported to CSV-files, with specific summer date 2023.08.04 in view. Both exports were performed on 8-th of November (winter, standard time), so GMT+2 offset was applied by default for all events, including summer of 2023 (and any other seasons and years as well). Without correction (shown at the right) the exported times for summer NFPs are 14:30. This is incorrect.

Economic Calendar Events with corrected timestamps

After empirical autodetection of the server's time zone, which was in effect during the summer, the library performs calendar export with time correction (shown at the left). As a result, the summer NFPs are moved to 15:30, as it should be. You can take a look at the chart for this period to make sure that correction is appropriate.

Nonfarm Payrolls on EURUSD H1 chart

This specific case is not so dramatic, because the non-corrected announced time 14:30 goes before 15:30, so expert advisers could probably keep waiting for the news and open trades. But when the server time zone is switched to summer, all winter events registered in the calendar contain timestamps delayed by 1 hour (!).

The stuff is still experimental. Feel free to send your feedback.

Further research on an impact of time corrections on news trading is planned. Stay tuned.


The attached mqh-files (CalendarFilter.mqh, CalendarCache.mqh, QuickSortStructT(Ref).mqh) contain bugfixes and improvements compared to their original versions from the book.



04.10.2024 - added writing/reading server time zone offset into cal-files and csv-files.

10.11.2024 - added an option to correct timestamps of events in the history in accordance to retrospective timezone changes of the server.

11.11.2024 - small bugfix and refinement in CalendarCache.mqh and CalendarFilter.mqh.

22.11.2024 - small bugfixes and improvements in CalendarCache.mqh.


Sample pine script stochastic divergence converted to MQL5 Sample pine script stochastic divergence converted to MQL5

A sample pine code converted to MQL

Push Notification for Opened / Closed Trades (Netting) Push Notification for Opened / Closed Trades (Netting)

This code provides a simple function for sending push notifications to your mobile device whenever trades are opened or closed in MetaTrader 5. It's designed for netting accounts (where only one position per symbol is allowed).

Swap Monitor Swap Monitor

This service periodically checks swaps for predefined symbols and saves detected changes into CSV-files for further analysis and potential replay (not implemented here). Also it monitors and alerts swap changes of existing positions.

AutoFibo indicator of two last swings based on ZigZag for MT5 AutoFibo indicator of two last swings based on ZigZag for MT5

The AutoFibo indicator is an advanced Fibonacci retracement tool that automatically draws Fibonacci levels based on the ZigZag pattern. This indicator is designed to help traders quickly identify potential support and resistance levels in trending markets.