What is prev_discretion ?
helloea: There should be a difference between rates_total and prev_discretion,
but my understanding should be wrong, because in the case of the reference file, rates_total and prev_discretion are the same.
There can be. First run prev_calculated is zero.
Otherwise, it is what you previously returned. Most examples return rates_total and thus have to check it on the next tick for first/previous run.
That is unnecessary if you return a correct value.
How
to do your lookbacks correctly.

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
In the MQL5 reference file, Oncalculate has two forms, the second above.
The MQL reference file shows the mechanism of the Oncalculate function:
1. Call only in custom metrics.
2. Oncalculate function is called every time the price changes.
3, can, with different price status (such as: open, close, etc.) to calculate the index.
4. Parameters:
(1) rates_total (total number of bars in the icon, including bars in the fluctuation?)
(2) prev_calculated (number of bars in the icon, excluding bars in the fluctuation?)
(3) all kinds of arrays (all kinds of data stored, used in calculating indicators)
5. The function returns: prev_calculated.
Question:
1. There should be a difference between rates_total and prev_discretion, but my understanding should be wrong, because in the case of the reference file, rates_total and prev_discretion are the same.
2. The two meanings in the reference documents are not understood at all. I hope the master can translate and guide.
We should note the connection between the return value of OnCalculate() and the second input parameter prev_calculated. During the function call, the prev_calculated parameter contains a value returned by OnCalculate() during previous call. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous run of this function.
For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal.
3. Oncalculate function whether there are other mechanisms, please master guidance, thank you.