#daily_hilo_01c
#https://usethinkscript.com/threads/need-help-with-existing-script-daily-high-low-bubble-that-displays-time.20759/
#Need help with existing script - Daily high/low bubble that displays TIME
#====================
#https://usethinkscript.com/threads/how-do-you-get-the-time-of-high-of-day.3751/page-2#post-97451
#SleepyZ
def na = double.nan;
def bn = barnumber();
def day = getday();
def newday = day != day[1];
def big = 99999;
def n = 1000;
input show_label = yes;
input show_bubbles = yes;
input showprice_in_bubble = yes;
#Time zone
input timezone = {default "ET", "CT", "MT", "PT"};
def starthour = (if timezone == timezone."ET" then 9
else if timezone == timezone."CT" then 8
else if timezone == timezone."MT" then 7
else 6);
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;
def hi;
def lo;
def hibn;
def lobn;
if bn == 1 then {
hi = 0;
lo = 0;
hibn = 0;
lobn = 0;
} else if newday and !isnan(close) then {
hi = fold a = 0 to n
with b
while getvalue(day,-a) == day and !isnan(getvalue(close,-a))
do max(b,getvalue(high,-a));
hibn = bn + (fold c = 0 to n
with d
while getvalue(day,-c) == day and getvalue(high,-c) != hi
do d+1);
lo = fold e = 0 to n
with f = big
while getvalue(day,-e) == day and !isnan(getvalue(close,-e))
do min(f,getvalue(low,-e));
lobn = bn + (fold g = 0 to n
with h
while getvalue(day,-g) == day and getvalue(low,-g) != lo
do h+1);
} else {
hi = hi[1];
lo = lo[1];
hibn = hibn[1];
lobn = lobn[1];
}
addchartbubble(show_bubbles and bn == hibn, hi,
"H: "+ (hour + ":") +
(if minutes < 10 then "0" + minutes else "" + minutes) + "\n" +
(if showprice_in_bubble then asdollars(high) else "")
, Color.WHITE
, yes);
addchartbubble(show_bubbles and bn == lobn, lo,
"L: "+ (hour + ":") +
(if minutes < 10 then "0" + minutes else "" + minutes) + "\n" +
(if showprice_in_bubble then asdollars(low) else "")
, Color.WHITE
, no);
def lasthihr = if bn == hibn then hour else lasthihr[1];
def lasthimin = if bn == hibn then minutes else lasthimin[1];
def lastlohr = if bn == lobn then hour else lastlohr[1];
def lastlomin = if bn == lobn then minutes else lastlomin[1];
addlabel(1, " ", color.black);
AddLabel(show_label,
"H: " + (lasthihr + ":") +
(if lasthimin < 10 then "0" + lasthimin else "" + lasthimin) + " | " +
Asdollars(hi), Color.WHITE);
addlabel(1, " ", color.black);
AddLabel(show_label,
"L: " + (lastlohr + ":") +
(if lastlomin < 10 then "0" + lastlomin else "" + lastlomin) + " | " +
Asdollars(lo), Color.WHITE);
addlabel(1, " ", color.black);
input show_hilo_lines = yes;
plot zhi = if show_hilo_lines and !isnan(close) and hi > 0 then hi else na;
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.light_gray);
zhi.setlineweight(1);
#zhi.hidebubble();
plot zlo = if show_hilo_lines and !isnan(close) and lo > 0 then lo else na;
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetDefaultColor(Color.light_gray);
zlo.setlineweight(1);
#zlo.hidebubble();
#---------------------------
input test_vlines = no;
addverticalline(test_vlines and bn == hibn,"-", color.green);
addverticalline(test_vlines and bn == lobn,"-", color.red);
addchartbubble(0 and newday, low,
hi + "\n" +
lo + "\n" +
hibn + "\n" +
lobn + "\n"
, color.yellow, no);
#