Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 15,897 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
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