
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
You have to check on forehand if the bar exists and when it does you can continue and read it's value.
But when it does not exist don't try to read it because it will go out of range and unload the indicator.
You don't understand.
'i' will cause error when you use it access an array directly (when i is out of range). But iOpen() and iClose() are function calls, and within that function calls, all necessary safeguards were incorporated to prevent error condition so that the return is 0 (worst case) rather than error.
Check how many bars there are by calling iBars(.... and then see if the bar that you are trying to read fit's within that range.
If there are only 100 bars you will get array out of range when trying to read bar 101..
A better solution would be to do your loops according to the amount of available bars because that way it will always match the number of available bars.There may be missing periods (This is what your image shows,) but there are no missing bars. If there are no ticks during a specific candle period there is no bar. There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles
No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum
What if, instead of Open[i]/Close[i], use iOpen()/iClose() instead? These functions will return value 0 if the bar does not exist - this way you can do a filtering, if necessary, of the return values before incorporating them into your calculation.
Thank you. It worked without previous error.
The answer was using iClose instead of Close.
Thank you. It worked without previous error.
The answer was using iClose instead of Close.