Using BarZone vs lhour with timezone

Posted By: Dalla

Using BarZone vs lhour with timezone - 01/09/19 09:00

I'm a bit puzzled as to the behavior of lhour() I'm seeing with the below two snippets.
The manual says:
"Closing local hour of the given bar in the given time zone (see timeOffset below), considering daylight saving time (see dst below). F.i. lhour(EST) returns the current hour at the New York Stock Exchange. If BarZone is set to the local zone, lhour() is identical to hour()."

Here we pass JST as timezone to lhour()
Code:
void run() {
	set(LOGFILE);
	int timezone = JST;
	//BarZone = JST;
	BarPeriod = 15;
   StartDate = 2010;
   EndDate = 2019;
	asset("USD/JPY");
	
	if(lhour(timezone) == 10 && minute() == 00) {
		enterShort();
	}
	if(lhour(timezone) == 12 && minute() == 30) {
		exitShort();
	}
}



Here instead we use BarZone, which if I understand correctly would set the zone of all bars to JST, meaning hour should return identical values to the code above.
Code:
void run() {
	set(LOGFILE);
	//int timezone = JST;
	BarZone = JST;
	BarPeriod = 15;
   StartDate = 2010;
   EndDate = 2019;
	asset("USD/JPY");
	
	if(hour() == 10 && minute() == 00) {
		enterShort();
	}
	if(hour() == 12 && minute() == 30) {
		exitShort();
	}
}



However these two snippets result in totally different backtests.
Did I missunderstand for BarZone vs lhour() works?
Posted By: Spirit

Re: Using BarZone vs lhour with timezone - 01/09/19 19:21

I thought hour() is UTC. You could print the hour and lhour to the log for checking.
© 2024 lite-C Forums