The solution entirely depends on what data you want to plot.
If all you are trying to do is to plot the High, Low and Close from the previous day but not include the extended trading session there is a much simpler way to do that:
def okToPlot = GetDay() == GetLastDay();
plot prevDayHigh = if okToPlot then high(period = AggregationPeriod.DAY)[1] else Double.NaN;
plot prevDayLow = if okToPlot then low(period = AggregationPeriod.DAY)[1] else Double.NaN;
plot prevDayClose = if okToPlot then close(period = AggregationPeriod.DAY)[1] else Double.NaN;
However if you are trying to include extended hours high and low while excluding the extended hours session from your chart it is 100% completely impossible to do.
Just an FYI to the newbies trying to learn how to write code. Don't try to learn from the code provided by the author of this post. That code is hideous. Looks like it was written by an engineer. Brute force all the way. 20 lines of code to accomplish the same task that can be completed in 3. Scary stuff.