Always check the "Bars" variable to make sure the index into Time[], High[], Low[], Close[], etc. will be valid or not.
This is especially important when running under the Strategy Tester with no "Use Date" limits, and during the first bar.
There will be no "mismatch" reported, because there is no mismatch. It simply just has the current bar data available.
Please can you explain what you mean by checking? I have the same issue. It is a pattern recognition EA that look for previous candles so use ratesH1[1], ratesH1[2], etc values and in the strategy tester it crash directly at the start because array out of range but in live markets work fine
Please can you explain what you mean by checking? I have the same issue. It is a pattern recognition EA that look for previous candles so use ratesH1[1], ratesH1[2], etc values and in the strategy tester it crash directly at the start because array out of range but in live markets work fine
@Mohammad Inanloo#: just check the oninit time in oninit function and save in global value
You should not access time series data in the OnInit() event handler, as the data may not be available yet (e.g. after opening MetaTrader and it is still not connected to the trade server or the chart data has not loaded yet).
Instead, do it in OnTick() when receiving the first tick.
Mohammad Inanloo #: bool checkTime = iTime(_Symbol, _Period, 1)> OnInitTime+( PeriodSeconds( _Period)*( Count Of candle you want to scape from starting point )) ;
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? 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(2006) No candle if open = close ? - MQL4 programming forum(2010)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thanks people,
checking the Bars value solved the problem.
Always check the "Bars" variable to make sure the index into Time[], High[], Low[], Close[], etc. will be valid or not.
This is especially important when running under the Strategy Tester with no "Use Date" limits, and during the first bar.
There will be no "mismatch" reported, because there is no mismatch. It simply just has the current bar data available.
Please can you explain what you mean by checking? I have the same issue. It is a pattern recognition EA that look for previous candles so use ratesH1[1], ratesH1[2], etc values and in the strategy tester it crash directly at the start because array out of range but in live markets work fine
Please can you explain what you mean by checking? I have the same issue. It is a pattern recognition EA that look for previous candles so use ratesH1[1], ratesH1[2], etc values and in the strategy tester it crash directly at the start because array out of range but in live markets work fine
If I am not mistaken, this could help
https://www.mql5.com/en/docs/series/bars
You should not access time series data in the OnInit() event handler, as the data may not be available yet (e.g. after opening MetaTrader and it is still not connected to the trade server or the chart data has not loaded yet).
Instead, do it in OnTick() when receiving the first tick.
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? 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 (2006)
No candle if open = close ? - MQL4 programming forum (2010)
Just compare the bar index to Bars.