#prev_hi_lo_clstocls
#https://usethinkscript.com/threads/looking-for-combined-high-low-for-pre-market-and-trading-hours.17852/
#Looking for combined High Low for pre-market and trading hours.
#TOS-man 2/16
#1
#For daily High Low indicators, either they show pre-market or trading hours.
#Is there thinkscript which shows combined HiLo starting from previous day close to today's close?
def na = Double.NaN;
def bn = barnumber();
#def d = GetDay();
#def day_first = d[1] != d[0];
# midnight
#def day_last = d[0] != d[-1];
#input st1 = 1600;
input st1 = 1500;
def last1 = secondstilltime(st1)[1] > 0 and secondsfromtime(st1) >= 0;
# verify last bar
#addverticalline(last1, "-", color.cyan);
def day_last = last1;
def prev_cls = if day_last then close else prev_cls[1];
#plot z1 = prev_cls;
def n = 1500;
def big = 99999;
def hi;
def lo;
if bn == 1 then {
hi = na;
lo = na;
} else if day_last then {
hi = fold e = 1 to n
with p
# while getvalue(d, -e) == d+1
while !getvalue(last1, -e)
do max(p, getvalue(high, -e));
lo = fold f = 1 to n
with q = big
# while getvalue(d, -f) == d+1
while !getvalue(last1, -f)
do min(q, getvalue(low, -f));
} else {
hi = hi[1];
lo = lo[1];
}
def en = hi != 0 and lo != big;
plot z1 = if en then hi else na;
plot z2 = if en then lo else na;
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.green);
#z1.setlineweight(1);
z1.hidebubble();
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetDefaultColor(Color.red);
#z2.setlineweight(1);
z2.hidebubble();
#