#higherlowerofday
#https://usethinkscript.com/threads/high-of-day-low-of-day-alert.18510/
#High of Day/Low of Day ALERT
def na = double.nan;
def bn = barnumber();
input start = 0930;
input end = 1600;
def firstbar = (secondsfromTime(start) == 0);
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def hi = if bn == 1 then 0
else if !daytime then 0
else if firstbar then high
else if daytime then max(high, hi[1])
else hi[1];
def lo = if bn == 1 then 0
else if !daytime then 0
else if firstbar then low
else if daytime then min(low, lo[1])
else lo[1];
def hihi = if firstbar then 0
else if daytime and hi != hi[1] then 1
else 0;
def lolo = if firstbar then 0
else if daytime and lo != lo[1] then 1
else 0;
alert(hihi, "higher high" ,alert.BAR, sound.DING);
alert(lolo, "lower low" ,alert.BAR, sound.bell);
plot zhihi = hihi;
zhihi.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zhihi.SetDefaultColor(Color.cyan);
zhihi.setlineweight(2);
zhihi.hidebubble();
plot zlolo = lolo;
zlolo.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
zlolo.SetDefaultColor(Color.yellow);
zlolo.setlineweight(2);
zlolo.hidebubble();
#---------------------
input test_lines = no;
plot zhi = if test_lines and hi > 0 then hi else na;
plot zlo = if test_lines and lo > 0 then lo else na;
addverticalline(test_lines and hihi, "-", color.green);
addverticalline(test_lines and lolo, "-", color.red);
#addverticalline(test_lines and firstbar,"-", color.cyan);
#