# days_back_00
def bn = barnumber();
def na = double.nan;
input days_back = 10;
def lastbarbn = highestall((if !isnan(close) then bn else 0)) ;
def lastbar = if bn == lastbarbn then 1 else 0;
def dow = GetDayOfWeek(getyyyymmdd());
def newday = dow[1] <> dow;
# ---------------------------------------
# desired day on chart
# forward day count
def daycnt = if bn == 1 then 0
else if newday then daycnt[1] + 1
else daycnt[1];
# max day number
def max_daycnt = highestall((if lastbar then daycnt else 0)) ;
# reverse day count
def revdaycnt = max_daycnt - daycnt + 1;
# ---------------------------------------
# chk if desired < maxdays
def dayback_ok = ( days_back < max_daycnt);
# desired day in the past
def dayx = if days_back == revdaycnt then 1 else 0;
addlabel(!dayback_ok, ">>>> chart doesn't have " + days_back + " days <<<<", color.cyan);
addlabel(1, "days back " + days_back + " / " + max_daycnt , color.yellow);
# ---------------------------------------
# desired bar of day (the current bar)
def barcnt = if bn == 1 then 0
else if newday then 1
else barcnt[1] + 1;
# bar count on last bar, the current bar
def desired_barcnt = highestall((if lastbar then barcnt else 0));
# max bar count
def max_barcnt = highestall(barcnt);
# desired bar in the past ( will trigger 1/day)
def barx = if barcnt == desired_barcnt then 1 else 0;
addlabel(1, "bar of day " + desired_barcnt + " / " + max_barcnt , color.yellow);
# ---------------------------------------
# desired bar in the past day
def bar_z = (dayx and barx);
# ---------------------------------------
input show_arrow_above_bar = yes;
def vert = 1.004;
plot bz = if (show_arrow_above_bar and bar_z) then (high * vert) else na;
bz.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bz.SetDefaultColor(Color.cyan);
bz.setlineweight(3);
bz.hidebubble();
# ---------------------------------------
# show a hollow candle surrounding the desired bar
input show_outline_around_bar = yes;
def soab = show_outline_around_bar;
def o = if (soab and bar_z) then open else na;
def h = if (soab and bar_z) then high else na;
def l = if (soab and bar_z) then low else na;
def c = if (soab and bar_z) then close else na;
def v = 0.01;
def o1 = (c * (1 + v));
def c1 = (o * (1 - v));
def h1 = (c * (1 + v));
def l1 = (o * (1 - v));
AddChart(growColor = Color.cyan, fallColor = Color.BLUE, neutralColor = Color.BLUE, high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);
# ---------------------------------------
input show_day_counts = yes;
addchartbubble(show_day_counts and newday, high*1.008, "F " + daycnt + "\nR " + revdaycnt, color.yellow, yes);
# ---------------------------------------
input show_test_bubble = no;
addchartbubble(show_test_bubble, low*0.99, bn
+ "\nN" + newday
+ "\nC" + daycnt
+ "\nD" + daycnt
+ "\nX" + max_daycnt
+ "\nR" + revdaycnt
+ "\n" + dayx
+ "\n" + barx
, (if bar_z then color.pink else if newday then color.cyan else if dayx then color.yellow else color.gray), no);
# ---------------------------------------
# addchart ref page
# https://usethinkscript.com/threads/candle-fill-color.6691/#post-70687
# post#9
#