Does it really matters what a refresh does to indicator buffers ? As you noted by yourself you should always initialize your buffers and refresh call OnCalculate with prev_calculated=0.
The rest is internal business of the platform. If you really want to know more, you can check it by yourself by comparing the values before and after a refresh.
Does it really matters what a refresh does to indicator buffers ? As you noted by yourself you should always initialize your buffers and refresh call OnCalculate with prev_calculated=0.
The rest is internal business of the platform. If you really want to know more, you can check it by yourself by comparing the values before and after a refresh.
At the end of the day I suppose it does not matter, although it was a burning curiosity, though apparently it has simmered down and I don't care anymore either :D
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I had a glitch on one of my indicator plotting lines which is meant only to be shown for the last 2 bars, which would sometimes show itself in historical bars when restarting MT5 after it was closed for a long time. Hitting refresh would fix it, but eventually I decided to head the problem off at the pass by making sure the first run of OnCalculate (0) would set all previous bars to EMPTY_VALUE.
Nonetheless, I am curious as to exactly what it is that "refresh" does.
I was assuming the issue was that because I had no logic in my indicator to actually initialize any past values in the buffer array, it was possible that random data in memory, or even old values that were not overwritten by other memory content in that array space, was leading to some old bars being plotted when MT5 was re-opened after being closed a long time. Because this only happened during times when MT5 was off for several hours, I assume this means the overall memory reservation or construct remained intact, occupying the same space as when starting MT5 up again. I should note that I had MetaEditor for that MT5 installation open the entire time, so perhaps that was keeping some memory reserved. I can't imagine this glitch only showing for the time MT5 was closed and then the current line buffer continuing to function at the same time for the current bar, without that space remaining reserved and continuing where it left off when restarting MT5.
My guess is that "refresh" wipes the slate clean for these buffer memory zones, re-establishing them as if they've been newly declared. After that, based on my test, it appears to set prev_calculated to 0 for either all the charts with that indicator, or all the charts. Perhaps it also wipes the memory for all charts/indicators as well. As far as I can tell, it does not re-initialize the indicators.
Edit: For your reference I have the plot for this buffer set to begin on the last 2 bars.
And on every new bar OnCalculate will clear out the 3rd last bar to empty_value (i'm wondering if it's possible for this to glitch if there is no tick for a new bar period and the next tick comes after skipping over a non-tick bar)
So when some bars were skipped while MT5 was closed, since it was already plotting before, and didn't get a chance to clear anything out on the next bars, multiple bars pass before MT5 being opened again, there will remain some artifacts, which I believe I have fixed by adding:
(edit 2: i and start were already declared earlier, they get reused for a bunch of stuff)