Unable to fetch the correct Previous Day close Price from 5 min Timeframe

It is not strange. The code is supposed to draw the previous session's high and low but not high and low of current session! So it does not look into future.

So of course at the start of current session it starts to plot extremes of previous day's session.

But there was code missing in previous post:

for ( i = 0; i < 4; i++ ) {  
  field = StrExtract("O,H,L,C", i);
  VarSet(field, IIf(time_window, VarGet(field), Null));
}

Of another threads code

So updated code

daysback = 2;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));

tn = TimeNum();
time_window = tn >= 93000 AND tn < 160000;
session_start = time_window AND NOT Ref(time_window,-1);

for ( i = 0; i < 4; i++ ) {  
  field = StrExtract("O,H,L,C", i);
  VarSet(field, IIf(time_window, VarGet(field), Null));
}

prev_high = Ref(HighestSince(session_start, H, 1), -1);
prev_high = ValueWhen(session_start, prev_high);

prev_low = Ref(LowestSince(session_start,Nz(L,1e9), 1), -1);
prev_low = ValueWhen(session_start, prev_low);

// PLOT SESSION PRICE ONLY
Plot( C, "Price", colorRed, styleBar );

RestorePriceArrays();// Restore Price arrays #############################################################

// PLOT ALL PRICE
Plot( C, "Price", colorDefault, styleBar );

Plot(prev_low, "LL", colorRed, styleStaircase);
Plot(prev_high, "HH", colorGreen, styleStaircase);

And here is picture where you can see that it plots previous dession high low at current session.