#col_compare_hod_lower
#https://usethinkscript.com/threads/need-help-building-a-custom-watchlist-column-for-hod.16150/
#Need help building a custom watchlist column for HOD
#Pyker Aug 5, 2023
#So i am looking for help to build a custom watchlist column that shows me when price is struggling with breaking the intraday HOD and keeps rejecting this area over multiple bars. So the watchlist column will paint red when price is within a HOD range, i am thinking HOD +- 1% away from hod price (or possibly 2%) will be good and i only want to see the column paint red when 3 or more bars have rejected this price area. See my attached images for examples of what i mean. So basically, when price is within the box and 3 or more bars have passed, the column turns red and if price goes below the box the column turns black again. Or if the price does breakout of box and make a new HOD, the column will also of course turn black again if/until the same conditions happens again.
#So the conditions are,
#1. When price is at HOD +- 1%
#2. When price has rejected HOD range for 3 or more bars
#If possible, it would be useful to know how many bars have passed by adding this number in the column. So for example, if 5 bars have passed, the column will count the bars and say 5.
# pick a % to define what is 'close' to hod
# price below hod more than x% = black
# first bar within x% of hod = cyan
# after x bars of being near hod = red
# new hod = green
def bn = BarNumber();
def na = Double.NaN;
def diffday = GetDay() != GetDay()[1];
input hod_near_percent = 0.4;
input min_near_qty = 3;
input price = high;
def hod = if bn == 1 then high
else if diffday then high
else if high > hod[1] then high
else hod[1];
def hod_near = hod * (1 - (hod_near_percent/100));
plot z1 = hod;
plot z2 = hod_near;
def first_near = (price > hod_near and price[1] < hod_near[1]);
def isnear = (price > hod_near and price < hod);
def is_near_qty = (sum(isnear, min_near_qty) >= min_near_qty);
# price below hod more than x% = black
# first bar or first few bars , within x% of hod = cyan
# after x bars of being near hod = red
# new hod = green
def near_num = if diffday then 0
else if price < hod_near then 0
else if is_near_qty then 2
else if first_near or isnear then 1
else if price > hod[1] then 3
else 0;
def vert = 0.0004;
plot z3 = high * (1 + vert);
z3.DefineColor("c0", color.black);
z3.DefineColor("c1", color.cyan);
z3.DefineColor("c2", color.red);
z3.DefineColor("c3", color.green);
z3.AssignValueColor(
if near_num == 0 then z3.color("c0")
else if near_num == 1 then z3.color("c1")
else if near_num == 2 then z3.color("c2")
else if near_num == 3 then z3.color("c3")
else color.black);
z3.SetPaintingStrategy(PaintingStrategy.POINTS);
#x.SetDefaultColor(Color.white);
z3.setlineweight(4);
z3.hidebubble();
#