How to get previous day Hourly closing values

Hello Everyone,

Please let me know how to get closing price of each hourly bars of yesterday. I am using exploration in 5 minutes time frame. I tried following code to do the same but it fails to detect new day during first hourly bar formation.

This is the scinario, market starts at 9:15 and first hourly bar closes at 10 am. During this time, If I try to detect new day using newday = Day() != Ref(Day(), -1) code, inside hourly time frame, it detects previous day first bar as new day not the current one. It works after 10 am.

So using following code, before 10 am If I scan for previous day hourly closing prices, I get closing price of day before yesterday.

Please help me how to resolve this problem.

TimeFrameSet(inHourly); //set hourly time frame
newday = Day() != Ref(Day(), -1);
barDate = ValueWhen(newday, Day(),2); //previous day date

startPrice = ValueWhen(newday, C, 2); //first bar price
bar2Price = ValueWhen(newday, Ref(C,-6), 1); //second bar price
bar3Price = ValueWhen(newday, Ref(C,-5), 1);
bar4Price = ValueWhen(newday, Ref(C,-4), 1);
bar5Price = ValueWhen(newday, Ref(C,-3), 1);
bar6Price = ValueWhen(newday, Ref(C,-2), 1);
bar7Price = ValueWhen(newday, Ref(C,-1), 1); //last bar price