datetime reverting with iTime/iBarShift bug?

 
   datetime dt = iTime(NULL, PERIOD_D1, 6);
   datetime dt2 = iTime(NULL, PERIOD_M5, iBarShift(NULL, PERIOD_M5, dt));
   Print(dt);
   Print(dt2);

When executing the above code, I get the following:

2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.17 23:55:00
2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.18 00:00:00

This does not make sense, as taking the iTime of the iBarShift of a certain datetime variable should just return that same datetime.

When doing the same for M15 or everything above, the datetimes dó match as expected. It seems to concern only M1 and M5.

Anyone seen something like this before or knows what's going on?

 
galantis:

When executing the above code, I get the following:

2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.17 23:55:00
2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.18 00:00:00

This does not make sense, as taking the iTime of the iBarShift of a certain datetime variable should just return that same datetime.

When doing the same for M15 or everything above, the datetimes dó match as expected. It seems to concern only M1 and M5.

Anyone seen something like this before or knows what's going on?

When I ran your code the dates were equal. But at day/shift 8 I got a similar error, probably because we're a day or so forward now.

I looped through 100 consecutive days and got a small number of seemingly random days in error; and for m15 and m30 as well, but not for H1, H4...

This one here for M1 at shift 8

Day 7 2019.12.17 00:00:00
Day 7 2019.12.17 00:00:00

Day 8 2019.12.16 00:00:00
Day 8 2019.12.13 23:59:00

===========

But if I make the iBarShift(.....true) I get

Day 7 2019.12.17 00:00:00
Day 7 2019.12.17 00:00:00

Day 8 2019.12.16 00:00:00
Day 8 1970.01.01 00:00

Not sure what that tells us, that there is no M1 for that time? Unless my code is wrong.




 
galantis:

When executing the above code, I get the following:

2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.17 23:55:00
2019.12.28 16:38:12.284    test EURUSD-ECN,H1: 2019.12.18 00:00:00

This does not make sense, as taking the iTime of the iBarShift of a certain datetime variable should just return that same datetime.

When doing the same for M15 or everything above, the datetimes dó match as expected. It seems to concern only M1 and M5.

Anyone seen something like this before or knows what's going on?

Because you can always have missing bar if there are no quotes, and the probability to have missing bars is the highest for M1 and decreases as the timeframe increases.

Specifically, in your example that means there is no M5 bar at 2019.12.18 00:00:00, so iBarShift returned the previous bar index.

 
You assume 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
          No candle if open = close ? - MQL4 programming forum
 
Missing bars make a lot of sense and you are all right indeed, they weren't existing. My apologies, I could have made this up myself if I've had zoomed in a little. Thanks for clearing this up.