hour() return wrong number

Posted By: Grat

hour() return wrong number - 06/17/20 08:53

Hi,

I have this code:
Code
#include <default.c>

string datetime(){
    return strf("%04d-%02d-%02d %02d:%02d", year(),month(),day(),hour(),minute());
}

function run()
{

    BarPeriod = 15;	// 15 min
    LookBack    = 0;
    assetList("Assets4");
    asset("EUR/USD");
    var dDateD=wdatef("%Y-%m-%d %H:%M", datetime());
    printf("\n%s is %d",datetime(),utm(dDateD));
}


real hour UTC is 8 but fce hour return 9

Where is problem ( see the picture )

Attached picture Snímek obrazovky 2020-06-17 v 13.49.16.png
Posted By: jcl

Re: hour() return wrong number - 06/17/20 09:38

hour() is not the current time. It's the time stamp of the current bar.

For the current time, use hour(NOW).
Posted By: Grat

Re: hour() return wrong number - 06/17/20 09:42

Yes, I know, but is in future. Only for first bar. For next one is OK
Posted By: jcl

Re: hour() return wrong number - 06/17/20 10:27

From the manual: "All date and time functions return 0 resp. invalid values in the initial run of the strategy since the bars and date ranges are not set up yet."

The time functions assume that the bar just ended. That's why you got the bar end time in the INITRUN, which is not in sync with the bars. In further runs the bar timestamp is just the current time.
Posted By: Grat

Re: hour() return wrong number - 06/17/20 11:03

Thank's,

every days is I learn new ... laugh
© 2024 lite-C Forums