I made another tests to make it more clear, without the timezone mess.
int asd = timeOffset(UTC, 1, 5, 0);
printf("current time: %d %d %d %d\n\n", month(0), day(0), hour(0), minute(0));
printf("offset time: %d %d %d %d", month(asd), day(asd), hour(asd), minute(asd));
if (hour(asd) != 5) printf(" !!!!!");
printf("\n");
printf("-----------\n");
Please see the attached picture.
- At monday (red zone) I am checking the previous day's 5AM bar.
- Surprisingly there is a trading day between monday and friday: sunday evening (orange zone), just a few bars. (Of course it's not that big surprise, it's because of the timezone shift.)
- ...but there are no bars in sunday at 5 AM.
- ...so i get the bar at friday 19:45.
Please help me understand the rules of the timeOffset behavior. Why I got that bar exactly? It's not even the last bar of friday.
As I see I need to make a custom search cycle to find the previous trading day's 5AM bar. It's OK.
But then why do we have the built-in timeOffset function, if we can't use on mondays? Or how should I use it correctly?