MTF mismatch

I usually backtest my EAs in Open Prices M1, simply because it is way too slow otherwise

I came up with a bug though.
I had a problem : my orders were opening at an hourly level, not a M1 level (despite using M1 OP in the strategy tester settings)
so I pinpointed down the error to an ATR Handle :  
If I changed the ATR TF, the whole tester starts using that timeFrame to open and close orders but only at the opening of an H1 candle.

and most bizzarely:
if I write :

atrHandle[i] = iATR(sym, PERIOD_H1, 14);
atrHandle2[i] = iATR(sym, PERIOD_M1, 14);
I got an error :

2026.09.18 16:36:27.707 CADCHF,M1: wrong timeframe request in Open Prices testing mode

but if I put atrHandle2 FIRST :

atrHandle2[i] = iATR(sym, PERIOD_M1, 14);
atrHandle[i] = iATR(sym, PERIOD_H1, 14);
then I got no error.
and if, in this configuration, I never even USE atrHandle2, it backtests with M1 precision, not H1....
so it seems that in OP M1 tester mode, the first requested timeFrame will be the timeFrame used for the backtester ?

is that strange ?!!! i don't understand
Jef

also if I use NULL instead of symbol name 'sym' it backtests in H1, not M1 anymore

so it seems related to the multipair somehow

atrHandle2[i] = iATR(NULL, PERIOD_M1, 14);
atrHandle[i] = iATR(sym, PERIOD_H1, 14);
Jean Francois Le Bas:
I usually backtest my EAs in Open Prices M1, simply because it is way too slow otherwise

I came up with a bug though.
I had a problem : my orders were opening at an hourly level, not a M1 level (despite using M1 OP in the strategy tester settings)
so I pinpointed down the error to an ATR Handle :  
If I changed the ATR TF, the whole tester starts using that timeFrame to open and close orders but only at the opening of an H1 candle.

and most bizzarely:
if I write :

I got an error :

2026.09.18 16:36:27.707 CADCHF,M1: wrong timeframe request in Open Prices testing mode

but if I put atrHandle2 FIRST :

then I got no error

It makes sense, to me at least, that the Tester having read the higher resolution M1 data first, can readily synchronize H1 data based on M1 data. In contrast thereto, synchronizing M1 data based on lower resolution H1 data─not so much.

Jean Francois Le Bas:
and if, in this configuration, I never even USE atrHandle2, it backtests with M1 precision, not H1....
so it seems that in OP M1 tester mode, the first requested timeFrame will be the timeFrame used for the backtester ?

That would seem to follow. In that case, you're simply not calling data from a 2nd timeframe.

Jean Francois Le Bas #:

also if I use NULL instead of symbol name 'sym' it backtests in H1, not M1 anymore

so it seems related to the multipair somehow

You should never use NULL without a specific reason for doing so. Access to ENUM_TIMEFRAMES is lost when you do that.

Ryan L Johnson #:

It makes sense, to me at least, that the Tester having read the higher resolution M1 data first, can readily synchronize H1 data based on M1 data. In contrast thereto, synchronizing M1 data based on lower resolution H1 data─not so much.

That would seem to follow. In that case, you're simply not calling data from a 2nd timeframe.

You should never use NULL without a specific reason for doing so. Access to ENUM_TIMEFRAMES is lost when you do that.

but the tester OpenPrice timeframe depends on the first request I make in the code, not the TF I selected ? I don't understand


and I never try to request M1 data on a H1 timeframe. I'm ALWAYS on a M1 timeframe, I don't change the timeframe of the strategy tester, yet the trading changes to H1 under certain conditions

No code to reproduce leads to guess or lack of answer.
Alain Verleyen #:
No code to reproduce leads to guess or lack of answer.
i'll make a code thanks
Jean Francois Le Bas #:
i'll make a code thanks
No need for code
  • The tested Expert Advisor cannot access data of a timeframe below the testing/optimization timeframe. For example, if your run testing/optimization on the H1 period, you can access data of H2, H3, H4 etc., but not M30, M20, M10 etc. In addition, the higher timeframes that are accessed must be multiple of the testing timeframe. For example, if you run testing on M20, you cannot access data of M30, but it is possible to access H1. These limitations are connected with the impossibility to obtain data of lower or non-multiple timeframes out of the bars generated during testing/optimization.
  • Limitations on accessing data of other timeframes also apply to other symbols whose data are used by the Expert Advisor. In this case the limitation for each symbol depends on the first timeframe accessed during testing/optimization. Suppose, during testing on EURUSD H1, an Expert Advisor accesses data of GBPUSD M20. In this case the Expert Advisor will be able to further use data of EURUSD H1, H2, etc., as well as GBPUSD M20, H1, H2 etc.
https://www.metatrader5.com/en/terminal/help/algotrading/tick_generation

so here is the simplest code I was able to make


just select "Open prices only" and set timeframe to M1 in the strategy tester and select "Visual Mode"

fdgh


if you set "LoadError" to true, you will have an error message in the logs:

EURUSD,M1: wrong timeframe request in Open Prices testing mode
2026.09.19 10:50:12.846 EURUSD: rates base receive error

LoadError = true:

2026.09.19 10:50:12.063 MetaTester 5 started on 127.0.0.1:3000
2026.09.19 10:50:12.068 cloud network mode is off
2026.09.19 10:50:12.068 initialization finished
2026.09.19 10:50:12.362 login (build 6182)
2026.09.19 10:50:12.580 20180 bytes of account info loaded
2026.09.19 10:50:12.580 1478 bytes of tester parameters loaded
2026.09.19 10:50:12.580 708 bytes of input parameters loaded
2026.09.19 10:50:12.581 489 bytes of symbols list loaded (96 symbols)
2026.09.19 10:50:12.581 expert file added: Experts\test M1 OP.ex5. 10382 bytes loaded
2026.09.19 10:50:12.599 10300 Mb available, 128 blocks set for ticks generating
2026.09.19 10:50:12.599 initial deposit 1000000.00 USD, leverage 1:100
2026.09.19 10:50:12.599 successfully initialized
2026.09.19 10:50:12.599 12 Kb of total initialization data received
2026.09.19 10:50:12.600 Intel Core i5-9400F  @ 2.90GHz, 32675 MB
2026.09.19 10:50:12.627 GBPUSD: symbol to be synchronized
2026.09.19 10:50:12.627 GBPUSD: symbol synchronized, 3720 bytes of symbol info received
2026.09.19 10:50:12.628 GBPUSD: history synchronization started
2026.09.19 10:50:12.631 GBPUSD: load 27 bytes of history data to synchronize in 0:00:00.001
2026.09.19 10:50:12.631 GBPUSD: history synchronized from 2009.01.01 to 2026.09.16
2026.09.19 10:50:12.708 GBPUSD,M1: history cache allocated for 502339 bars and contains 480736 bars from 2021.01.04 00:05 to 2022.04.22 23:55
2026.09.19 10:50:12.708 GBPUSD,M1: history begins from 2021.01.04 00:05
2026.09.19 10:50:12.711 GBPUSD,M1 (RoboForex-ECN): OHLC bar states generating. OnTick executed on the bar begin only
2026.09.19 10:50:12.711 GBPUSD,M1: testing of Experts\test M1 OP.ex5 from 2022.04.25 00:00 to 2022.05.14 00:00 started with inputs:
2026.09.19 10:50:12.711   loadError=true
2026.09.19 10:50:12.727 EURUSD: symbol to be synchronized
2026.09.19 10:50:12.728 EURUSD: symbol synchronized, 3720 bytes of symbol info received
2026.09.19 10:50:12.728 EURUSD: history synchronization started
2026.09.19 10:50:12.731 EURUSD: load 27 bytes of history data to synchronize in 0:00:00.001
2026.09.19 10:50:12.731 EURUSD: history synchronized from 2009.01.01 to 2026.08.14
2026.09.19 10:50:12.780 EURUSD,H1: history cache allocated for 8502 bars and contains 8142 bars from 2021.01.04 00:00 to 2022.04.22 23:00
2026.09.19 10:50:12.780 EURUSD,H1: history begins from 2021.01.04 00:00
2026.09.19 10:50:12.828 GBPUSD,H1: history cache allocated for 8501 bars and contains 8141 bars from 2021.01.04 00:00 to 2022.04.22 23:00
2026.09.19 10:50:12.828 GBPUSD,H1: history begins from 2021.01.04 00:00
2026.09.19 10:50:12.846 EURUSD,M1: wrong timeframe request in Open Prices testing mode
2026.09.19 10:50:12.846 EURUSD: rates base receive error
2026.09.19 10:50:12.846 log file "C:\Users\tooss\AppData\Roaming\MetaQuotes\Tester\5CAEF2E03C733716C25D808FDC03747C\Agent-127.0.0.1-3000\logs\20260919.log" written
2026.09.19 10:50:12.846 test Experts\test M1 OP.ex5 on GBPUSD,M1 thread finished
2026.09.19 10:50:12.854 prepare for shutdown
2026.09.19 10:50:12.854 shutdown finished

LoadError = false :

2026.09.19 10:49:21.805 MetaTester 5 started on 127.0.0.1:3000
2026.09.19 10:49:21.810 cloud network mode is off
2026.09.19 10:49:21.810 initialization finished
2026.09.19 10:49:22.103 login (build 6182)
2026.09.19 10:49:22.330 20180 bytes of account info loaded
2026.09.19 10:49:22.330 1478 bytes of tester parameters loaded
2026.09.19 10:49:22.330 708 bytes of input parameters loaded
2026.09.19 10:49:22.330 489 bytes of symbols list loaded (96 symbols)
2026.09.19 10:49:22.331 expert file added: Experts\test M1 OP.ex5. 10382 bytes loaded
2026.09.19 10:49:22.347 10606 Mb available, 132 blocks set for ticks generating
2026.09.19 10:49:22.347 initial deposit 1000000.00 USD, leverage 1:100
2026.09.19 10:49:22.347 successfully initialized
2026.09.19 10:49:22.347 12 Kb of total initialization data received
2026.09.19 10:49:22.347 Intel Core i5-9400F  @ 2.90GHz, 32675 MB
2026.09.19 10:49:22.375 GBPUSD: symbol to be synchronized
2026.09.19 10:49:22.375 GBPUSD: symbol synchronized, 3720 bytes of symbol info received
2026.09.19 10:49:22.376 GBPUSD: history synchronization started
2026.09.19 10:49:22.379 GBPUSD: load 27 bytes of history data to synchronize in 0:00:00.001
2026.09.19 10:49:22.379 GBPUSD: history synchronized from 2009.01.01 to 2026.09.16
2026.09.19 10:49:22.452 GBPUSD,M1: history cache allocated for 502339 bars and contains 480736 bars from 2021.01.04 00:05 to 2022.04.22 23:55
2026.09.19 10:49:22.452 GBPUSD,M1: history begins from 2021.01.04 00:05
2026.09.19 10:49:22.454 GBPUSD,M1 (RoboForex-ECN): OHLC bar states generating. OnTick executed on the bar begin only
2026.09.19 10:49:22.454 GBPUSD,M1: testing of Experts\test M1 OP.ex5 from 2022.04.25 00:00 to 2022.05.14 00:00 started with inputs:
2026.09.19 10:49:22.454   loadError=false
2026.09.19 10:49:22.470 EURUSD: symbol to be synchronized
2026.09.19 10:49:22.471 EURUSD: symbol synchronized, 3720 bytes of symbol info received
2026.09.19 10:49:22.485 EURUSD: history synchronization started
2026.09.19 10:49:22.488 EURUSD: load 27 bytes of history data to synchronize in 0:00:00.001
2026.09.19 10:49:22.488 EURUSD: history synchronized from 2009.01.01 to 2026.08.14
2026.09.19 10:49:22.559 EURUSD,M1: history cache allocated for 504509 bars and contains 482906 bars from 2021.01.04 00:05 to 2022.04.22 23:55
2026.09.19 10:49:22.559 EURUSD,M1: 1 bar from 2022.04.25 00:05 added
2026.09.19 10:49:22.559 EURUSD,M1: history begins from 2021.01.04 00:05
2026.09.19 10:49:22.649 final balance 1000000.00 USD
2026.09.19 10:49:22.660 GBPUSD,M1: 83059 ticks, 21210 bars generated. Environment synchronized in 0:00:00.042. Test passed in 0:00:00.288.
2026.09.19 10:49:22.660 GBPUSD,M1: total time from login to stop testing 0:00:00.330 (including 0:00:00.043 for history data synchronization)
2026.09.19 10:49:22.660 167118 total ticks for all symbols
2026.09.19 10:49:22.660 EURUSD: generate 84059 ticks in 0:00:00.000, passed to tester 84059 ticks
2026.09.19 10:49:22.660 GBPUSD: generate 83059 ticks in 0:00:00.000, passed to tester 83059 ticks
2026.09.19 10:49:22.660 134 Mb memory used including 58 Mb of history data, 64 Mb of tick data
2026.09.19 10:49:22.660 log file "C:\Users\tooss\AppData\Roaming\MetaQuotes\Tester\5CAEF2E03C733716C25D808FDC03747C\Agent-127.0.0.1-3000\logs\20260919.log" written
2026.09.19 10:49:22.660 test Experts\test M1 OP.ex5 on GBPUSD,M1 thread finished
2026.09.19 10:49:22.668 prepare for shutdown
2026.09.19 10:49:22.668 shutdown finished

you can see that by simply creating a handle on H1, any further request of M1 TF will fail

the engine will follow the timeframe of the first requested TF

Jef

Files:
Jean Francois Le Bas #:

so here is the simplest code I was able to make


just select "Open prices only" and set timeframe to M1 in the strategy tester and select "Visual Mode"


you can see that by simply creating a handle on H1, any further request of M1 TF will fail

the engine will follow the timeframe of the first requested TF

Jef

Limitations on accessing data of other timeframes also apply to other symbols whose data are used by the Expert Advisor. In this case the limitation for each symbol depends on the first timeframe accessed during testing/optimization. Suppose, during testing on EURUSD H1, an Expert Advisor accesses data of GBPUSD M20. In this case the Expert Advisor will be able to further use data of EURUSD H1, H2, etc., as well as GBPUSD M20, H1, H2 etc.

Solution :

      SymbolSelect(sym, true);
      iTime(sym,PERIOD_M1,0);
      if (loadError == true)    
         DummyHandle[j] = iATR(sym,PERIOD_H1,14); 

However I discovered a problem (MT5 bug) while checking. Thanks for the code.

Alain Verleyen #:

Solution :

However I discovered a problem (MT5 bug) while checking. Thanks for the code.

thanks that's the "temporary" solution that I had found : start with requesting a M1 timeframe then you can use any TF 


could you share what is the bug you found tho ? i'm interested

Jean Francois Le Bas #:

thanks that's the "temporary" solution that I had found : start with requesting a M1 timeframe then you can use any TF 

It's not a temporary solution. It's standard solution.

could you share what is the bug you found tho ? i'm interested

If you run LoadError = false, then LoadError = true the error doesn't trigger. That you could call it a temporary solution, in my opinion it's a bug (incoherent behaviour).