limit will be -1 if prev_calculated is 0
limit will be -1 if prev_calculated is 0
Thanks.
I was confused by pre_calculated.
It seems prev_calculated frequently set Zero,right?
As per the statement about OnCalculate() in the manual MQL5 as below:
"
We should noted 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.
"
As the pice changed frequently, so paremeterr pre_calculated is set to zero frequently ?
it will burden the indicator calculation, right ???
limit will be -1 if prev_calculated is 0
Thank you. Now it is OK.
Revised as below:
//--- check for rates
if(rates_total<2)
return(0);
//--- preliminary calculations
limit = prev_calculated-1;
if (limit<0) limit=0;
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use