hi @Alexibg1000
Actually I’ve seen this behavior in MT5, especially when using ZigZag with the Strategy Tester.
CopyRates() may already return the new H1 bar at index 0, while ZigZag hasn’t finished updating its buffer yet. Because of that, shifting the data 2–3 bars isn’t a good solution—it can add unnecessary lag.
I’d check both the price series and indicator state before processing:
if(!SeriesInfoInteger(_Symbol, PERIOD_H1, SERIES_SYNCHRONIZED))
return;
if(BarsCalculated(zigzag_handle) <= 0)
return;
Also use iTime() to detect a new bar instead of comparing Open/Close values.
There isn’t a single function that forces everything to synchronize at exactly the same moment. It’s better to handle it as:
new bar → series ready → indicator calculated → CopyBuffer() → process
I use this kind of separation in MT5 EA development because it avoids unnecessary bar delays and makes tester behavior more predictable.
Hello,
I’ve encountered issues with the bar data retrieval functions—CopyRates, CopyOpen, Copy..., etc. I am running tests on 6–7 years of historical data using the "Strategy Tester." To get straight to the point: I’ve run into situations where the `OnTimer` event triggers and a bar is added—one that hasn't actually started generating yet—appearing at index 0 with identical Open and Close values. In other instances, that same bar is missing entirely, forcing me to rely on earlier bars that have already been processed. You might suggest implementing validation or time checks; I’ve already tried those approaches, which is why I’m posting here now. Is there a way to avoid this issue? Is there a function that forces bar synchronization? The last few times I debugged my bot using visual mode, I observed discrepancies: a bar would appear on the chart but be missing from the buffer, or conversely, a bar wouldn't have started drawing yet but would already exist in the buffer.
The bot runs alongside a ZigZag indicator, and shifting the data by 2–3 bars causes significant lag. I am testing on a one-hour timeframe.
Thanks in advance!
Insufficient information to get a useful answer.
You need to provide code, logs, settings, etc...
hi @Alexibg1000
Actually I’ve seen this behavior in MT5, especially when using ZigZag with the Strategy Tester.
CopyRates() may already return the new H1 bar at index 0, while ZigZag hasn’t finished updating its buffer yet. Because of that, shifting the data 2–3 bars isn’t a good solution—it can add unnecessary lag.
I’d check both the price series and indicator state before processing:
if(!SeriesInfoInteger(_Symbol, PERIOD_H1, SERIES_SYNCHRONIZED))
return;
if(BarsCalculated(zigzag_handle) <= 0)
return;
Also use iTime() to detect a new bar instead of comparing Open/Close values.
There isn’t a single function that forces everything to synchronize at exactly the same moment. It’s better to handle it as:
new bar → series ready → indicator calculated → CopyBuffer() → process
I use this kind of separation in MT5 EA development because it avoids unnecessary bar delays and makes tester behavior more predictable.
Thanks for help! I don't think that there is a problem with a ZigZag. I tested it before adding bar data collection, and it worked perfect. After i started reading bar data, missmaches started appearing, and they are from bars. I will check the function SeriesInfoInteger :-) , i hope it will help me
I’ve run into situations where the `OnTimer` event triggers and a bar is added—one that hasn't actually started generating yet—appearing at index 0 with identical Open and Close values. In other instances, that same bar is missing entirely,
What increment of time is your timer set at?
Note that the relevant documentation states that:
In general, when the timer period is reduced, the testing time is increased, as the handler of timer events is called more often (https://www.mql5.com/en/docs/event_handlers/ontimer).
I experienced issues in the Tester while running a millisecond timer, so I conditionally switched back to OnTick() using MQLInfoInteger(MQL_TESTER).
As Alain Verleyen alluded, we're left to guess without details.
Thanks for help! I don't think that there is a problem with a ZigZag. I tested it before adding bar data collection, and it worked perfect. After i started reading bar data, missmaches started appearing, and they are from bars. I will check the function SeriesInfoInteger :-) , i hope it will help me
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I’ve encountered issues with the bar data retrieval functions—CopyRates, CopyOpen, Copy..., etc. I am running tests on 6–7 years of historical data using the "Strategy Tester." To get straight to the point: I’ve run into situations where the `OnTimer` event triggers and a bar is added—one that hasn't actually started generating yet—appearing at index 0 with identical Open and Close values. In other instances, that same bar is missing entirely, forcing me to rely on earlier bars that have already been processed. You might suggest implementing validation or time checks; I’ve already tried those approaches, which is why I’m posting here now. Is there a way to avoid this issue? Is there a function that forces bar synchronization? The last few times I debugged my bot using visual mode, I observed discrepancies: a bar would appear on the chart but be missing from the buffer, or conversely, a bar wouldn't have started drawing yet but would already exist in the buffer.
The bot runs alongside a ZigZag indicator, and shifting the data by 2–3 bars causes significant lag. I am testing on a one-hour timeframe.
Thanks in advance!