input xbarsinside = 2;
input in_xdays = 5;
input agg = AggregationPeriod.DAY;
def isInsideBar = high(period = agg) < high(period = agg)[1] and
low(period = agg) > low(period = agg)[1];
input pricecolor = yes;
AssignPriceColor( if !pricecolor
then color.current
else if isInsideBar
then Color.YELLOW else Color.CURRENT);
#Current includes inside bar today; Prior excludes today's inside bar, if any
input display = {default current, prior};
def xdaysinside = Sum(isInsideBar, in_xdays) >= xbarsinside;
def xpriordaysinside = Sum(isInsideBar[1], in_xdays) >= xbarsinside;
input showlabels = yes;
AddLabel(showlabels and display == display.current and xdaysinside, "Current", Color.YELLOW);
AddLabel(showlabels and display == display.prior and xpriordaysinside, "Prior", Color.YELLOW);
input showbubbles = yes;
AddChartBubble(showbubbles and IsNaN(close[2]) and !IsNaN(close[3]) and display == display.current and xdaysinside[3], close[3], "Current", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[2]) and !IsNaN(close[3]) and display == display.prior and xpriordaysinside[3], close[3], "Prior", Color.YELLOW);
;