#Previous Day's Highs/Lows extended to the right edge
input showtodayonly = yes;
def na = Double.NaN;
script prior {
input daysback = 1;
input agg = AggregationPeriod.HOUR;
#Days Defined
def ymd = GetYYYYMMDD();
def candles = !IsNaN(close);
def capture = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;
#def high using hProfile
profile vol = VolumeProfile("startNewProfile" = thisDay != thisDay[1], "onExpansion" = no, "numberOfProfiles" = 15, "pricePerRow" = .01, "value area percent" = 70);
def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
#Find High of Agg Period Bar on Daysback
def high_agg = if thisDay == daysback then hProfile else high_agg[1];
def high_agg_bar = if thisDay == daysback and high(period = agg) == high_agg then BarNumber() else Double.NaN;
plot priorhigh_agg = high_agg;
priorhigh_agg.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Find low of Agg Period Bar on Daysback
#def high using hProfile
def lProfile = if IsNaN(vol.GetLowest()) then lProfile[1] else vol.GetLowest();
#Find Low of Agg Period Bar on Daysback
def low_agg = if thisDay == daysback then lProfile else low_agg[1];
def low_agg_bar = if thisDay == daysback and low(period = agg) == high_agg then BarNumber() else Double.NaN;
plot priorlow_agg = low_agg;
priorlow_agg.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
}
plot ph1 = if showtodayonly and GetDay() != GetLastDay() then na else prior(1);
plot pl1 = if showtodayonly and GetDay() != GetLastDay() then na else prior(1).priorlow_agg;
ph1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot ph2 = if showtodayonly and GetDay() != GetLastDay() then na else prior(2);
plot pl2 = if showtodayonly and GetDay() != GetLastDay() then na else prior(2).priorlow_agg;
ph2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot ph3 = if showtodayonly and GetDay() != GetLastDay() then na else prior(3);
plot pl3 = if showtodayonly and GetDay() != GetLastDay() then na else prior(3).priorlow_agg;
ph3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DefineGlobalColor("H", Color.CYAN);
DefineGlobalColor("L", Color.MAGENTA);
ph1.SetDefaultColor(GlobalColor("H"));
ph2.SetDefaultColor(GlobalColor("H"));
ph3.SetDefaultColor(GlobalColor("H"));
pl1.SetDefaultColor(GlobalColor("L"));
pl2.SetDefaultColor(GlobalColor("L"));
pl3.SetDefaultColor(GlobalColor("L"));
input bubble = yes;
input bubblemover = 1;
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), ph1[b1], "PH1", ph1.TakeValueColor());
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), pl1[b1], "PL1", pl1.TakeValueColor(), no);
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), ph2[b1], "PH2", ph2.TakeValueColor());
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), pl2[b1], "PL2", pl2.TakeValueColor(), no);
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), ph3[b1], "PH3", ph3.TakeValueColor());
AddChartBubble(bubble and IsNaN(close[b]) and !IsNaN(close[b1]), pl3[b1], "PL3", pl3.TakeValueColor(), no);
#