Hi!
I'm experiencing an issue I don't recall seeing before: when OnCalculate inside a custom indicator is called for the first time, "prev_calculated" comes with 0. Once the first processing happens, the OnCalculate is finished with "return rates_total". So, in the next call of OnCalculate, prev_calculate = rates_total, that is, the indicator will start the new check from where it stopped before. The exception would be moments where a whole update is called (e.g. by clicking in the Graph with the right button and than in "Update").
Well that is not what is happening to me: I call an indicator, most notably when I open MT5, the indicator is first loaded normally and then, out of nowhere, OnCalculate is once again called with prev_calcualted = 0:
EA code:
So why is that second call with prev_calculated = 0 happening? Note: it does so both when the market is open as well as when it's closed.
Well I guess I found my answer:
https://www.mql5.com/en/forum/326514
:3

- 2019.11.15
- www.mql5.com
Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi!
I'm experiencing an issue I don't recall seeing before: when OnCalculate inside a custom indicator is called for the first time, "prev_calculated" comes with 0. Once the first processing happens, the OnCalculate is finished with "return rates_total". So, in the next call of OnCalculate, prev_calculate = rates_total, that is, the indicator will start the new check from where it stopped before. The exception would be moments where a whole update is called (e.g. by clicking in the Graph with the right button and than in "Update").
Well that is not what is happening to me: I call an indicator, most notably when I open MT5, the indicator is first loaded normally and then, out of nowhere, OnCalculate is once again called with prev_calcualted = 0:
EA code:
So why is that second call with prev_calculated = 0 happening? Note: it does so both when the market is open as well as when it's closed.