# hilo_in_time_periods_02
#--------------------
#https://usethinkscript.com/threads/dollar-amount-and-time.15924/
#Dollar Amount and Time
# show the dollar amount a stock has fallen or moved up from 9 AM to 11 AM.
#-----------------------------
def bn = BarNumber();
def na = Double.NaN;
input start = 1000;
input stop = 1200;
addlabel(1, " " , color.black);
addlabel(1, "start time " + asprice(start), color.yellow);
addlabel(1, "stop time " + asprice(stop), color.yellow);
def first = SecondsTillTime(start) == 0;
def period = (SecondsFromTime(start) >= 0 and SecondsTillTime(stop) > 0);
def big = 99999;
def hi;
def lo;
if first and !isnan(close) then {
hi = fold j1 = 0 to 500
with k1
while !isnan(getvalue(close, -j1)) and GetValue(period, -j1)
do (if GetValue(high, -j1) > k1 then GetValue(high, -j1) else k1);
lo = fold j2 = 0 to 500
with k2 = big
while !isnan(getvalue(close, -j2)) and GetValue(period, -j2)
do (if GetValue(low, -j2) < k2 then GetValue(low, -j2) else k2);
} else if period then {
hi = hi[1];
lo = lo[1];
} else {
hi = 0;
lo = 0;
}
def rng = hi-lo;
plot zhi = if hi > 0 then hi else na;
plot zlo = if lo > 0 then lo else na;
zhi.setdefaultcolor(color.light_gray);
zlo.setdefaultcolor(color.light_gray);
zhi.hidebubble();
zlo.hidebubble();
input show_bubble = yes;
addchartbubble(show_bubble and first, lo,
"Hi - Lo\n" +
rng
, color.yellow, no);
#