You could put a button on the chart and then when it is pressed have your code do whatever you want.
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?
Thanks.
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?
Thanks.
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.
Charles Stangor: 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.
| Fix your broken indicator. Print in OnCalculate() Not in OnInit(). No reload, no button, done. |
Fix your broken indicator. Print in OnCalculate() Not in OnInit(). No reload, no button, done. |
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?
Thanks!
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!
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.
Thanks everyone!
Still amazed there's no way to just refresh the indicator.
And the reason there is no "refresh", is because you are supposed to code the indicator properly and not to code a "hack-job" that needs to be refreshed! Please note that it is not in anyway an attack on you, but just a comedic observation to illustrate the point!
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!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.
Thanks.