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.
That's not a bug. You have to deal with it, as you can perfectly get the same on a live chart.
cre8iveq:
A backtest, by definition is supposed to get the same results as a live test, or as close to it as possible
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 ?
Marco vd Heijden:
Please Marco.
Who told you that ?
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
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.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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)