So I have an indicator and I print some stuff to the chart in OnInit(). It doesn't need to occur regularly. Is there a way to call OnInit() from the chart? To reload the indicator I guess. I was thinking Refresh would do it, but no.
OK, yes that would work. Or just exit and reload MT5.
But what does the "refresh" button do?
And shouldn't there be a way to reload the indicator?
Better to either have a keystroke or button do it like Keith says, or run it on a fixed timer.
Calling OnInit() at random times can have some unintended consequences elsewhere, depending on how your code is written.
OK, despite all the helpful comments I'm still unsure how to reload an indicator so that OnInit() fires again.
I need to read a pretty big file from disk, but I only need to read it occasionally.
It's not practical to read it on every call of OnCalculate().
If I change the value of a parameter in an indicator in MT5, the indicator is deinitialized and then reinitialized.
I want to create that process-- I can figure out how to create a button but what should the button call to create the reinitialization?
As @whroeder1 stated, it is an incorrect practice to call OnInit() or reload the Indicator, when the correct way is to do it in the OnCalculate(). No one said, that is has to occur on every call to OnCalculate(), only that the processing be done there.
So, in the OnCalculate() have a decision be made based on what ever conditions you expect - if NO then continue as normal, but if YES, then reread you external data file and then print whatever you need, and rerun the calculations on all the buffers if required.
Simple as that. No mess, no fuss!
OK, right, so use a button or script to write a global variable and use that to trigger within OnCalculate(). Guess that's simple as pie.
Still amazed there's no way to just refresh the indicator.
I'm definitely a trader not a coder (obviously I guess). Spent years with NinjaTrader but finding mql5 a hundred times more useful. Despite the excellent documentation however it does come with a learning curve.
Thanks for the tips Fernando!