User mistake, was: Get DateNum() in ValueWhen()

Please teach me, why this code bellow give the result not correct?
I don't known, why D1 == D2 but LastValue(D1) != LastValue(D2)?

if (BeginZoom != "") 
{
	dn = DateNum();
	dt = DateTime();
	be = 1190424;
	en = be + 1;
	
	newbar = (dn != Ref(dn, -1)) AND (dn == be OR dn == en);
	
	D1  = ValueWhen(newbar, dt, 0); 
	D2  = ValueWhen(newbar, dt, 1);
	sD1 = DateTimeToStr(LastValue(D1), 3);
	sD2 = DateTimeToStr(LastValue(D2), 3);
	
	PopupWindow ("" + NumToStr(D1) + " | " + sD1 + "\n" + NumToStr(D2) + " | " + sD2, "");
	
	AB = CreateObject("Broker.Application");
	AW = AB.ActiveWindow;
	AW.ZoomToRange(sD1, sD2);
}

Untitled

Could you specifically write your intention in words?

I wanna ZoomToRange() of a day in Intraday chart. Example day 24/04/2019 (1190424). It mean show all bars (tick) since the market opened until the market closed.

Did you go through this KB Article?
How to browse charts in selected date range

Also found a solution shared by fxshrat:

And if that's the sole intention, then why not simply use Bar Replay window?

1 Like

Thank you for helping me!