
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
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
Also, what point are you trying to make with your post?
Actually that's not correct.
prev_calculated will not say something about what the indicator has or has not done. It will contain whatever you returned from the last call to OnCalculate(), i.e. during processing of the last tick. The documented name is a mis-nomer, instead of "prev_calculated" it should be "prevReturnValue". For example it will happily return any negative value you return from OnCalculate(). Or anything else completely unrelated to the indicator, e.g. tomorrows temperature of your local weather forecast (if you wish so).
You can use it for communicating a value to the next call (the intended functionality). But be aware that its usefulness is limited as the terminal will overwrite your return value with 0 (zero) if IndicatorCounted() returns 0 (zero). So, it's better to store values intended for processing by the next function call elsewhere, e.g. in a global variable.
General (and better understandable) approach:
Most of the examples in documentation, forum and code base on how to correctly resolve the amount of changed bars are wrong.Thank you @alphatrading for this UNDERSTANDABLE explanation.
Actually that's not correct.
prev_calculated will not say something about what the indicator has or has not done. It will contain whatever you returned from the last call to OnCalculate(), i.e. during processing of the last tick. The documented name is a mis-nomer, instead of "prev_calculated" it should be "prevReturnValue". For example it will happily return any negative value you return from OnCalculate(). Or anything else completely unrelated to the indicator, e.g. tomorrows temperature of your local weather forecast (if you wish so).
Actually that's not correct.
While you can return any value in OnCalculate(), prev_calculated will NOT be set to whatever value you returned on the last call. It will be bound between 0 and rates_total-1. You just can't use it for whatever you want.
You can use it for communicating a value to the next call (the intended functionality). But be aware that its usefulness is limited as the terminal will overwrite your return value with 0 (zero) if IndicatorCounted() returns 0 (zero). So, it's better to store values intended for processing by the next function call elsewhere, e.g. in a global variable.
General (and better understandable) approach:
Most of the examples in documentation, forum and code base on how to correctly resolve the amount of changed bars are wrong.Give me a simple explanation for rates_total and prev_calculated in OnCalculate function.
https://docs.mql4.com/basis/function/events
Recommended video explaining rates total, prev calculated indicator counted.