I am building a new indicator using the OnCalculate function for the first time. As I'm going through the logic in my brain, I can't get past the problem of what to do if I have multiple For loops that depend on prev_calculated settings when a recall occurs in the middle of a For loop. For example, a recall of OnCalculate occurs at iteration 162 of For loop 1, and prev_calculated is set at 162 upon re-entry of the OnCalculate function. For loop 1 continues where it was interrupted and completes its job. Here is where I see a problem... For Loop 2 is now using the prev_calculated value of 162 as the starting point, never processing bars 0 through 161. Can someone please shed some light on how to get through this? It may be something simple that I don't understand about how OnCalculate works, but I want to get past this so I can continue with the logic for my Indicator. Thank you in advance!
- OnCalculate function
- Problem in OnCalculate()
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
Why would there be a recall of OnCalculate before all code in the indicator is executed?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register