# day_hilo_cnts
#https://usethinkscript.com/threads/tos-high-low-count-script.17960/
declare lower;
def na = Double.NaN;
def bn = BarNumber();
def en = !isnan(close);
def d = GetDay();
def newday = d != d[1];
def lastday = d == getlastday();
input only_last_day = yes;
def hi = if bn == 1 then 0 else if newday then high else Max(hi[1], high);
def lo = if bn == 1 then 0 else if newday then low else Min(lo[1], low);
def hidaycnt = if bn == 1 then 0
else if only_last_day and d != getlastday() then 0
else if en and newday then 0
else if hi > hi[1] then hidaycnt[1] + 1
else hidaycnt[1];
plot z1 = hidaycnt;
def lodaycnt = if bn == 1 then 0
else if only_last_day and d != getlastday() then 0
else if en and newday then 0
else if lo < lo[1] then lodaycnt[1] + 1
else lodaycnt[1];
plot zlo = -lodaycnt;
def bigger = if (hidaycnt - lodaycnt) >= 0 then hidaycnt else -lodaycnt;
def smaller = if (hidaycnt - lodaycnt) >= 0 then -lodaycnt else hidaycnt;
#input min_number = 5;
#plot scan = if absvalue(bigger) >= min_number then 1 else 0;
addlabel(1, " ", color.black);
addlabel(1, "hi " + hidaycnt, color.green);
addlabel(1, " ", color.black);
addlabel(1, "lo " + (lodaycnt), color.red);
#addlabel(1, "b " + bigger, color.gray);
#addlabel(1, (hidaycnt - lodaycnt), color.magenta);
#addlabel(1, bigger + " / " + smaller, color.gray);
addlabel(1, " ", color.black);
addlabel(1,
(if bigger < 0 then "-" else "") + (if bigger < 10 and bigger > -10 then "0" else "") + absvalue(bigger) +
" / " +
(if smaller < 0 then "-" else "") + (if smaller < 10 and smaller > -10 then "0" else "") + absvalue(smaller)
#, color.gray);
, (if bigger > 0 then color.green else if bigger < 0 then color.red else color.gray));
#assignbackgroundcolor(if bigger > 0 then color.green else if bigger < 0 then color.magenta else color.gray);
#