Gamestudio Links
Zorro Links
Newest Posts
Removing outliers from files
by AndrewAMD. 12/02/26 15:26
SGT_FW
by Aku_Aku. 11/30/26 08:19
Experiences with cTrader
by JeyKey II. 11/27/26 09:04
make a complaint
by EW_bytes. 11/26/26 23:00
FXCM => AVA Trade Plugin???
by Martin_HH. 11/25/26 21:59
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
What are you working on?
by rayp. 11/20/26 18:10
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 8,567 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
timeOffset mistake #488885
09/11/25 18:41
09/11/25 18:41
Joined: Jan 2022
Posts: 81
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 81
Budapest
Hello,

I am planning to use timeOffset, to determine the previous day's bar at a given time.
Sample:
Code
...
int timezone = CET;
if (lhour(timezone, 0) == 10 && minute(0) == 0){
    int asd = timeOffset(timezone, 1, 5, 0);
    printf("current time: %d %d %d %d\n", month(0), day(0), lhour(timezone, 0), minute(0));
    printf("offset time: %d %d %d %d\n", month(asd), day(asd), lhour(timezone, asd), minute(asd));
    printf("-----------\n");
}


Result:
Code
...
current time: 5 29 10 0
offset time: 5 28 5 0
-----------
current time: 5 30 10 0
offset time: 5 29 5 0
-----------
current time: 5 31 10 0
offset time: 5 30 5 0
-----------
current time: 6 3 10 0
offset time: 5 31 21 45
...


So usually it behaves as it expected:
at 10 AM, with timeOffset I get the previous day's 5AM bar, which is correct.
However at mondays, as you see in the last two lines:
  • I checked at candle 2024-06-03 10:00 AM
  • Expected result: 2024-05-31 05:00 AM
  • Result I got: 2024-05-31 21:45 AM


(If you want to double-check, please keep in mind that it's 2024 data. So in 2025, 06-03 is not monday, but in 2024 it is.)

Do you have any idea why is this wrong? Is it a bug, or I am missing something?

Last edited by NorbertSz; 09/11/25 19:31.
Re: timeOffset mistake [Re: NorbertSz] #488888
09/13/25 11:25
09/13/25 11:25
Joined: Jan 2022
Posts: 81
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 81
Budapest
I made another tests to make it more clear, without the timezone mess.
Code
    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?

Attached Files fsmm.png
Last edited by NorbertSz; 09/14/25 11:53.
Re: timeOffset mistake [Re: NorbertSz] #488889
09/13/25 11:53
09/13/25 11:53
Joined: Jan 2022
Posts: 81
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 81
Budapest
Solution for previous day's hour and minute bar:
Code
int getBarFromPreviousDay(int h, int m, int tz = UTC){
    const int currentDay = day(0);
    for (int i = 1; i <= LookBack; i++) {
        if (day(i) == currentDay) continue;
        if (lhour(tz, i) == h && minute(i) == m) return i;
    }
    printf("No bar found for previous day at %02d:%02d within LookBack period.\n", h, m);
    return -1;
}

Last edited by NorbertSz; 09/13/25 11:54.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1