Economic Calendar CSV - MetaTrader 5 Script | Trading Script Download - MT4/MT5 Resources





This is an extended version of the script CalendarForDates.mq5 presented in the Algorithmic Trading book .
Input variables allow you to specify the country code, current code, and time range to filter the required records. If the input is left blank, the full calendar can be requested (if the calendar is requested for the first time after the terminal is started, downloading its underlying data may take a while or even timeout and produce no results - then please run the script again).
As a result, you will get a CSV file containing the calendar records and the most important fields (not all fields will be exported - feel free to adapt the source code to your needs).
Alternatively, it is possible to enter a *.cal file (an archived copy of the calendar at a specific time) created by the indicator CalendarMonitorCached.mq5 also described in the book and now obsolete, replaced by its extended version CalendarMonitorCachedTZ.mq5 (recommended and required for new functionality, as described below).
The most interesting feature: This script demonstrates the use of the time server DST.mqh to adjust the timestamps of historical events based on the server's past time zone changes, which are persistently reflected in the timestamps of candles. This mode enables per-symbol history fix cache times by setting the input to true .
Saving corrected and uncorrected events to a CSV file allows you to easily compare the impact of time correction on historical records.
In order to use this function correctly, it is recommended to run the script on the XAUUSD or EURUSD H1 chart. When used programmatically, these symbols should be passed to the time server's daylight saving time functions.
The same method is used in the indicator CalendarMonitorCachedTZ.mq5 for exporting time-corrected calendar events into archived cal files, ready for loading from inside the tester, thus ensuring accurate backtesting and optimization of the news robot.
The date range for performing time correction is limited to the maximum number of bars of the time range H1 on the chart . This is the specificity of the empirical method used inside Time Server DST.mqh .
Let's consider a specific event type, preferably one that has a large impact on the market, such as the release of US Non-Farm Payrolls (NFP) data.
On European servers with DST schedule (MQ demo) it happens at 14:30 in winter and 15:30 in summer. In the screenshot below you can see 2 versions of the complete calendar history exported to a CSV file side by side, where you can see the specific summer date August 04, 2023. Both exports were performed on November 8th (winter, standard time), so a GMT+2 offset is applied by default to all events, including summer 2023 (and any other seasons and years). Uncorrected (shown on the right), the export time for summer NFP is 14:30. This is incorrect.
After automatically detecting the server time zone based on experience (valid during summer), the library performs a calendar export with time correction (as shown in the left image). Therefore, the summer NFP data is moved to 15:30, as it should be. You can look at the chart for that period to make sure the correction is appropriate.

These things are still in the experimental stage. Please feel free to send your feedback.
Further research into the impact of timing corrections on news trading is planned. stay tuned.
The attached mqh files ( CalendarFilter.mqh, CalendarCache.mqh, QuickSortStructT(Ref).mqh ) contain bug fixes and improvements compared to the original versions in the book.
04.10.2024 - Added write/read server time zone offset in cal files and csv files.
10.11.2024 - Added an option to correct the timestamp of events in history based on the server's retroactive time zone changes.
November 11, 2024 - Minor bugfixes and improvements in CalendarCache.mqh and CalendarFilter.mqh.
November 22, 2024 - Minor bug fixes and improvements in CalendarCache.mqh.
Attachment download
📎 autoptr.mqh (1.86 KB)
📎 calendardefines.mqh (4.66 KB)
📎 calendarfiltercached.mqh (2.38 KB)
📎 defines.mqh (0.71 KB)
📎 is.mqh (0.98 KB)
📎 quicksortstructt.mqh (3.97 KB)
📎quicksortstructtref.mqh (7.86 KB)
📎 stringutils.mqh (1.91 KB)
📎 calendarfilter.mqh (28.8 KB)
📎 timeserverdst.mqh (15.68 KB)
📎 calendarcache.mqh (28.54 KB)
📎calendarcsvfordates.mq5 (11.88 KB)
Source: MQL5 #52977
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •