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.
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)