Indicators: Economic Calendar Monitor and Cache for Backtesting on History

 

Economic Calendar Monitor and Cache for Backtesting on History:

This indicator displays current events on the chart and allows you to export the calendar to archives for backtesting, automatically fixing time discrepancies between the history of bars and the history of events. This is an improved version of CalendarMonitorCached indicator from the algotrading book.

Economic Calendar Monitor and Cache for Backtesting on History

Author: Stanislav Korotky

 
Do you have PRTF.mqh? (file 'MQL5\Include\MQL5Book\PRTF.mqh' not found CalendarCache.mqh 7 11)
 
Ulises Ulpiano Cune #:
Do you have PRTF.mqh? (file 'MQL5\Include\MQL5Book\PRTF.mqh' not found CalendarCache.mqh 7 11)

I found  it https://www.mql5.com/en/code/45593

MQL5 Programming for Traders – Source Codes from the Book. Part 4
MQL5 Programming for Traders – Source Codes from the Book. Part 4
  • www.mql5.com
In the fourth part of the book, we will focus on mastering built-in functions (MQL5 API) and will gradually delve into specialized subsystems. Any MQL5 program can utilize a plethora of technologies and functionalities. Therefore, it makes sense to begin with the most simple and useful functions that can be utilized in most programs.
 
Ulises Ulpiano Cune #:
Do you have PRTF.mqh? (file 'MQL5\Include\MQL5Book\PRTF.mqh' not found CalendarCache.mqh 7 11)

Thank you for pointing this out. This is an omission. I added the header to this indicator as well. I don't know how did it pass the automatic check-up during submission without this file.

 
Further research on news trading is published in the blogpost about backtesting of the expert adviser with the calendar cache.
Backtesting news trading based on economic calendar history with adjusted timings
Backtesting news trading based on economic calendar history with adjusted timings
  • www.mql5.com
This blogpost presents some further results of experiments with news trading based on the built-in calendar of MetaTrader 5 and MQL5. Originally, the idea was implemented in the algotrading book as a
 

HI, i've a problem with adjustTZonHistory or with my code ;-) I tried to save the cache file with adjustTZonHistory and without adjustTZonHistory - but the news events are always wrong in the tester. Shifted by 1 hour or by 2 hours.


The code i used:

   newsfilter_cache = new CalendarCache("calendar_cache.cal", true);
   if(newsfilter_cache[].isLoaded())
     {
      Print("Newsfilter: using cache...");
      newsfilter_filter = new CalendarFilterCached(newsfilter_cache[]);
     }
   else
     {
      if(MQLInfoInteger(MQL_TESTER))
        {
         Alert("Can't run in the tester without calendar cache file");
         Print("Can't run in the tester without calendar cache file");
         return false;
        }

      newsfilter_cache = new CalendarCache();

      newsfilter_cache[].adjustTZonHistory(_Symbol, true);

      if(!newsfilter_cache[].save("calendar_cache.cal"))
        {
         Print("Error: ", _LastError);
        }

Thanks for your help!


Output is:

2025.01.06 22:16:55.523  (EURUSD.PRO,M1)        Binding calendar tables...
2025.01.06 22:16:55.587  Edge EA (EURUSD.PRO,M1)        Time fix-up started at 2015.10.19 04:00:00
2025.01.06 22:16:55.587  Edge EA (EURUSD.PRO,M1)        2015.10.19 04:00:00: 57673 -10800 diff=-3600
2025.01.06 22:16:55.588  Edge EA (EURUSD.PRO,M1)        2015.12.20 23:00:00: 104987 -7200 OK
2025.01.06 22:16:55.588  Edge EA (EURUSD.PRO,M1)        2016.04.25 01:50:00: 12153 -10800 diff=-3600
2025.01.06 22:16:55.590  Edge EA (EURUSD.PRO,M1)        2017.01.01 02:00:00: 91725 -7200 OK
2025.01.06 22:16:55.590  Edge EA (EURUSD.PRO,M1)        2017.05.07 05:00:00: 57967 -10800 diff=-3600
2025.01.06 22:16:55.591  Edge EA (EURUSD.PRO,M1)        2017.11.12 23:00:00: 91925 -7200 OK
2025.01.06 22:16:55.592  Edge EA (EURUSD.PRO,M1)        2018.03.19 01:50:00: 22855 -10800 diff=-3600
2025.01.06 22:16:55.593  Edge EA (EURUSD.PRO,M1)        2018.12.09 03:30:00: 59322 -7200 OK
2025.01.06 22:16:55.594  Edge EA (EURUSD.PRO,M1)        2019.05.06 02:30:00: 96423 -10800 diff=-3600
2025.01.06 22:16:55.596  Edge EA (EURUSD.PRO,M1)        2019.12.01 02:00:00: 111551 -7200 OK
2025.01.06 22:16:55.596  Edge EA (EURUSD.PRO,M1)        2020.04.27 03:30:00: 120361 -10800 diff=-3600
2025.01.06 22:16:55.598  Edge EA (EURUSD.PRO,M1)        2020.11.22 23:45:00: 134124 -7200 OK
2025.01.06 22:16:55.599  Edge EA (EURUSD.PRO,M1)        2021.04.19 00:30:00: 148783 -10800 diff=-3600
2025.01.06 22:16:55.600  Edge EA (EURUSD.PRO,M1)        2021.11.14 12:45:00: 215452 -7200 OK
2025.01.06 22:16:55.601  Edge EA (EURUSD.PRO,M1)        2022.04.04 01:50:00: 153015 -10800 diff=-3600
2025.01.06 22:16:55.602  Edge EA (EURUSD.PRO,M1)        2022.11.07 04:00:00: 165962 -7200 OK
2025.01.06 22:16:55.602  Edge EA (EURUSD.PRO,M1)        2023.03.12 23:30:00: 182049 -10800 diff=-3600
2025.01.06 22:16:55.604  Edge EA (EURUSD.PRO,M1)        2023.11.06 01:50:00: 169270 -7200 OK
2025.01.06 22:16:55.604  Edge EA (EURUSD.PRO,M1)        2024.03.11 01:50:00: 181258 -10800 diff=-3600
2025.01.06 22:16:55.606  Edge EA (EURUSD.PRO,M1)        2024.11.04 02:30:00: 208469 -7200 OK
2025.01.06 22:16:55.607  Edge EA (EURUSD.PRO,M1)        Binding calendar tables...


Another hint:? relevant?

TimeServerGMTOffset() is -7200 while live but it is 0 when in stress tester.

i tested 3 news events in tester (all is fine while "live"):
05.06.2023 16:45 records[i].time but in reality: 15:45 Uhr
03.11.2023 16:45 records[i].time but in reality: 14:45 Uhr
26.12.2024 15:30 records[i].time but in reality: 14:30 Uhr (Initial Jobless Claims)

 
disaster123 #:

HI, i've a problem with adjustTZonHistory or with my code ;-) I tried to save the cache file with adjustTZonHistory and without adjustTZonHistory - but the news events are always wrong in the tester. Shifted by 1 hour or by 2 hours.

The code i used:

Output is:

Another hint:? relevant?

TimeServerGMTOffset() is -7200 while live but it is 0 when in stress tester.

i tested 3 news events in tester (all is fine while "live"):
05.06.2023 16:45 records[i].time but in reality: 15:45 Uhr
03.11.2023 16:45 records[i].time but in reality: 14:45 Uhr
26.12.2024 15:30 records[i].time but in reality: 14:30 Uhr (Initial Jobless Claims)

Try other symbols (if you have other EURUSD or XAUUSD), use H1 timeframe, make sure you did not apply the adjustment twice. Try to set #define PRINT_DST_DETAILS before includes and look at the detailed logs.

Can you confirm that my indicator is also showing wrong times?

TimeServerGMTOffset() is only for online! In the tester use TimeServerGMTOffsetHistory.

 
Stanislav Korotky #:

Can you confirm that my indicator is also showing wrong times?

Dear Stanislav - thanks for your help and comment. This is already EURUSD. The adjustment is only done once - it's only called in def init(). Regarding your indicator (you mean CalendarMonitorCachedTZ.mq5) - do i need to look at it in backtesting? Does this work for an indicator?

 

This is only about Tick data Duckascopy vs. Broker Ticks - as this seems also to be a problem.

I also detected that my imported Duckascopy Tick Data matches sometimes my broker tick data and sometimes not. Most probably due to timezone switching. How can i have to match the news my imported tick data? And how to verify - seems pretty complicated...

Thanks again!

 
It seems that even live cal data of this summer does not match my brokers tick data as they're out of "line"... this is so ugly. Using the cache file - matches my broker data / chart again. But how to solve this for external data like dukascopy?
 
disaster123 #:
It seems that even live cal data of this summer does not match my brokers tick data as they're out of "line"... this is so ugly. Using the cache file - matches my broker data / chart again. But how to solve this for external data like dukascopy?

OK got it working. I needed to convert my duckascopy data to USD+7 DST US broker times. After that everything matched. Thanks for all your hard work and library.

 
What happens if multiple EAs use the cache at the same time?