def NA = Double.NaN;
input agg = AggregationPeriod.DAY;
input showOnlyLastPeriod = no;
input showBubbles = yes;
input showValuesInBubbles = yes;
input spaceBetween = 1;
plot currentOpen;
plot prevDayClose;
plot prevDayLow;
plot prevDayHigh;
def exp = IsNaN(close[spaceBetween]);
currentOpen = if exp then open("period"=agg) else NA;
prevDayClose = if exp then close("period"=agg)[1] else NA;
prevDayLow = if exp then low("period"=agg)[1] else NA;
prevDayHigh = if exp then high("period"=agg)[1] else NA;
AddChartBubble(showBubbles, if IsNaN(currentOpen[1]) and !IsNaN(currentOpen) then currentOpen else NA, if showValuesInBubbles then "CurrOpen $"+currentOpen else "CurrOpen", Color.WHITE, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayClose[1]) and !IsNaN(prevDayClose) then prevDayClose else NA, if showValuesInBubbles then "PrevClose $"+prevDayClose else "PrevClose", Color.YELLOW, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayLow[1]) and !IsNaN(prevDayLow) then prevDayLow else NA, if showValuesInBubbles then "PrevLow $"+prevDayLow else "PrevLow", Color.RED, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayHigh[1]) and !IsNaN(prevDayHigh) then prevDayHigh else NA, if showValuesInBubbles then "PrevHigh $"+prevDayHigh else "PrevHigh", Color.GREEN, yes);
currentOpen.SetDefaultColor(Color.WHITE);
prevDayLow.SetDefaultColor(Color.RED);
prevDayHigh.SetDefaultColor(Color.GREEN);
prevDayClose.SetDefaultColor(Color.YELLOW);
currentOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
declare once_per_bar;
declare hide_on_daily;
def Globex_Open = 1630;
def Globex_Close = 0930;
def today = GetDay() == GetLastDay();
#change plots to if today then globexhigh else double.nan;
def h = high;
def l = low;
def globexOpen = secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>0;
def globexReset = globexOpen and !globexOpen[1];
def globexHigh = compoundValue(1, if((h > globexHigh[1] and globexOpen) or globexReset, h, globexHigh[1]), h);
def globexLow = compoundValue(1, if((l < globexLow[1] and globexOpen) or globexReset, l, globexLow[1]), l);
plot Globex_High = globexHigh;
Globex_High.HideBubble();
Globex_High.HideTitle();
plot Globex_Low = globexLow;
Globex_Low.HideBubble();
Globex_Low.HideTitle();