MQL5 - History cache

 

In the back tester, I switched from H4 to D1, and the EA died.

So, I dug into the problem.

It turns out that I have an iMA I use for determining trend with a period of 320.

Granted that 320 hours is very different from 320 days, and I would likely scale this value back for logical considerations, I was curious about why the EA died.

It turns out BarsCalculated() continued to return -1.

Then I saw this in the "headers" for the test run:

2018.01.05 17:39:08.563 USDCHF: symbol to be synchronized
2018.01.05 17:39:08.563 USDCHF: symbol synchronized, 3464 bytes of symbol info received
2018.01.05 17:39:08.563 USDCHF: history synchronization started
2018.01.05 17:39:08.566 USDCHF: load 27 bytes of history data to synchronize in 0:00:00.000
2018.01.05 17:39:08.566 USDCHF: history synchronized from 2013.01.02 to 2017.12.29
2018.01.05 17:39:08.685 USDCHF,Daily: history cache allocated for 1303 bars and contains 259 bars from 2013.01.02 00:00 to 2013.12.31 00:00
2018.01.05 17:39:08.685 USDCHF,Daily: history begins from 2013.01.02 00:00
2018.01.05 17:39:08.686 USDCHF,Daily (FxPro-MT5): OHLC bar states generating. OnTick executed on the bar begin only
2018.01.05 17:39:08.686 USDCHF,Daily: testing of Experts\Mr-Pulse.ex5 from 2014.01.01 00:00 to 2017.12.31 00:00 started with inputs:

Changing the iMA period to < 259 fixes the issue, no problem.

However, I am curious as to what is going on. As you can see, my test run goes from 2014.01.01 to 2017.12.31, which is four years, mas o menos. But the history cache is somehow a limitation.

So . . . what is the best way to handle this in the code?

 

1 year of history is expected behaviour for D1 and below.

Start your test sooner and code your EA to not "die".

 
Alain Verleyen:

Start your test sooner . . .

Oh, interesting!

I changed the start date to 1 day before, and I got:

2018.01.05 18:37:03.209    USDCHF,Daily: history cache allocated for 1565 bars and contains 389 bars from 2012.07.02 00:00 to 2013.12.30 00:00

Not that this will be my solution, but I do have a better sense of what's going on.

Thanks for the response.

 
Anthony Garot:

Oh, interesting!

I changed the start date to 1 day before, and I got:

2018.01.05 18:37:03.209    USDCHF,Daily: history cache allocated for 1565 bars and contains 389 bars from 2012.07.02 00:00 to 2013.12.30 00:00

Not that this will be my solution, but I do have a better sense of what's going on.

Thanks for the response.

Seems "1 year" is very variable thing for Metaquotes :-D

The general solution is to start (320-259)= 61 days sooner so 2013.11.01. Arrived on 2014.01.01 you will have at least 320 bars in history and your real test can start.

 

I'm having same issue.

This is the log that I get when I run my EA on strategy tester.

2020.04.19 13:48:52.884 EURUSD,Weekly: history cache allocated for 70 bars and contains 53 bars from 2018.12.30 00:00 to 2019.12.29 00:00

I use some indicators on W1 timeframe with more than 53 as its period (example 100).

I'm not able to get indicator values until my W1 charts get at least 100 candle: it makes sense.

Is there no way to force MT5 to load more candle when test starts?

Only thing that can be done is start test X periods before in order to arrive at desired "start" point with enough bars loaded on chart?