Indicators: Economic Calendar Monitor and Cache for Backtesting on History - page 2

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

Calendar cache-file is normally read just once at MQL-program startup and then the cache is served from memory, but if you want be 100% sure there will be no conflicts, you can modify source code in CalendarCache.mqh a bit, where the file opens:

   bool load(const string filename, const int flags = 0)
   {
      if(!StringLen(filename)) return false;
      PrintFormat("Loading calendar %s '%s'", (flags ? "common" : "cache"), filename);
      t = 0;
      int handle = LOG(FileOpen(filename, FILE_READ | FILE_BIN | flags | FILE_SHARE_READ));
      if(handle == INVALID_HANDLE) return false;
      ...

To access the cache from multiple tester agents you can place it in the common folder, but this is applicable only for local PC optimizations.

You don't need my indicator for your EA backtesting, I only asked about it because it's known to work on ordinary brokers (see below), and you could make a subtle modification to the source code which inteferes. Indicators can be tested standalone in the tester in visual mode.

Quality of 3-rd party ticks, as well as quotes segmentation (alignment by day/week boundary) can be tricky and non-standard in history of some brokers - then the empirical method used for autodetection of timezone will fail.

 
OK thx a lot again! I didn't mean multiple testers using the file but multiple live EAs.
 
Do i need to run  in online mode always when using live and do i need one cache per EA?
 
disaster123 #:
Do i need to run  in online mode always when using live and do i need one cache per EA?

Online you don't need a cache - read calendar directly (the lib can do it transparently just to keep the source code unified).

A single cache per PC is enough, or you can prefer to have separate caches for each terminal instance.

Create new cache just before you are going to do tests/optimizations up to current date.

 
Stanislav Korotky #:

Online you don't need a cache - read calendar directly (the lib can do it transparently just to keep the source code unified).

A single cache per PC is enough, or you can prefer to have separate caches for each terminal instance.

Create new cache just before you are going to do tests/optimizations up to current date.

OK thx!

 
Stanislav Korotky #:

Online you don't need a cache - read calendar directly (the lib can do it transparently just to keep the source code unified).

A single cache per PC is enough, or you can prefer to have separate caches for each terminal instance.

Create new cache just before you are going to do tests/optimizations up to current date.

I'm currently always create a new cache in case an EA starts not in tester. But this seems to result in the following errors:


a few thousand lines of:

Can't read quotes for 2025.01.16 10:50:52, error: 4003 INVALID_PARAMETER

as well as sometimes:

array out of range in 'CalendarCache.mqh' (694,22)

 
disaster123 #:

I'm currently always create a new cache in case an EA starts not in tester. But this seems to result in the following errors:

Can you send a short source code to reproduce the problem?

The error "Can't read quotes for" comes from TimeServerDST.mqh and means that you, most likely, call it with somewhat incorrect parameters, for example which asks for future quotes. Also make sure the terminal is connected and the work symbol is synchronized when you call the lib.

In the CalendarCache.mqh try to edit the line 159:

if(!n) return -1;false;
 
Stanislav Korotky #:

Can you send a short source code to reproduce the problem?

The error "Can't read quotes for" comes from TimeServerDST.mqh and means that you, most likely, call it with somewhat incorrect parameters, for example which asks for future quotes. Also make sure the terminal is connected and the work symbol is synchronized when you call the lib.

In the CalendarCache.mqh try to edit the line 159:

yes sure no problem. The no quotes error happens also for very old dates and it happens between FixCachedTimesBySymbolHistory and Newsfilter: using online mode - i've a feeling that there are too many requests tot the online calendar to broker.


Code is this:

   if(MQLInfoInteger(MQL_TESTER))
     {
      newsfilter_cache = new CalendarCache("calendar_cache.cal", true);

      if(newsfilter_cache[].isLoaded())
        {
         Print("Newsfilter: using cache...");
         newsfilter_filter = new CalendarFilterCached(newsfilter_cache[]);

         int tzoffset = newsfilter_cache[].getTZOffset();
         PrintFormat("Current server TZ offset: %+d; calendar cached TZ offset: %+d",
                     MQLInfoInteger(MQL_TESTER) ? TimeServerGMTOffset() : TimeServerGMTOffsetHistory(), tzoffset);

        }
      else
        {
         Alert("Can't run in the tester without calendar cache file");
         Print("Can't run in the tester without calendar cache file");
         return false;
        }
     }
   else
     {

      newsfilter_cache = new CalendarCache();

      Print("FixCachedTimesBySymbolHistory");
      newsfilter_cache[].adjustTZonHistory("XAUUSD", true);

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

      Print("Newsfilter: using online mode");
      newsfilter_filter = new CalendarFilter();
     }

   CalendarFilter *f = newsfilter_filter[];

   if(!f.isLoaded())
     {
      Print("ERROR Cal Filter not loaded!");
      return false;
     }
 
disaster123 #:

yes sure no problem. The no quotes error happens also for very old dates and it happens between FixCachedTimesBySymbolHistory and Newsfilter: using online mode - i've a feeling that there are too many requests tot the online calendar to broker.


Code is this:

Without a context (how the fragment is called), settings, and logs, it's hard to deduce what can be wrong, apart from the fact that CopyTime function can really fail - it does not mean that the lib violates something. According to your current report, this completely legitimate line fails:

CopyTime(symbol, PERIOD_H1, 0, Bars(symbol, PERIOD_H1), array)

I meant that you could provide a complete test EA to reproduce the problem.

Alternatively, since you have the source codes, you can set the breakpoint at the line in TimeServerDST.mqh, where the message is printed out, and then run your program under debugger. When/if the problem appears, your code will fall into debugger, and you can check what's wrong.

Probably, there is something special in your environment (work instrument, temporary connection loss, etc.).

 
argh - i got it! XAUUSD is not a valid symbol at OX - you need to use XAUUSD.PRO for timezone adjustment.... bad...