Bug in MQL5 (Backtest Only)

cre8iveq
2954
cre8iveq  

Put this code in the OnInit() function...

   nATRHandle = iATR(_Symbol, PERIOD_CURRENT, nATRPeriod);

   Comment(CopyBuffer(nATRHandle, 0, 0, 2, arrATR));

If you run this in a live chart, you'll see exactly what you expect... CopyBuffer returns 2. If you run it on a backtest, you'll see CopyBuffer returns -1. An error code. You'll see CopyBuffer returns -1, which is an error code. Why can we not access indicators in OnInit()... wouldn't that be kind of useful? (it took me hours to figure out why this wasn't working)


Anthony Garot
5265
Anthony Garot  

cre8iveq:

Why can we not access indicators in OnInit()

https://www.mql5.com/en/forum/227456#comment_6542317

cre8iveq:

wouldn't that be kind of useful?

Maybe.

cre8iveq:

(it took me hours to figure out why this wasn't working)

Sorry that happened. At least you won't do it again.

Alain Verleyen
41514
Alain Verleyen  
That's not a bug. You have to deal with it, as you can perfectly get the same on a live chart.
cre8iveq
2954
cre8iveq  
The fact that one thing happens on a live chart, and a different thing happens in the backtest makes it a bug. A backtest, by definition is supposed to get the same results as a live test, or as close to it as possible
Marco vd Heijden
Moderator
13504
Marco vd Heijden  
cre8iveq:
 A backtest, by definition is supposed to get the same results as a live test, or as close to it as possible

Who told you that ?

Alain Verleyen
41514
Alain Verleyen  
Marco vd Heijden:

Who told you that ?

Please Marco.
Alain Verleyen
41514
Alain Verleyen  
cre8iveq:
The fact that one thing happens on a live chart, and a different thing happens in the backtest makes it a bug. A backtest, by definition is supposed to get the same results as a live test, or as close to it as possible

This is not a bug, it's how MT5 is working.

Don't use this code in OnInit(), the tester doesn't have time to launch the indicator.