study("Premarket High/Low", overlay=true)
ending_hour = input(defval=9, title="Ending Hour", type=input.integer)
ending_minute = input(defval=30, title="Ending Minute", type=input.integer)
atr_factor = input(title="ATR Faktor", type=input.float, defval=1)
aftermarket = input(title="Include Aftermarket", type=input.bool, defval=false)
// LastOnly = input(title="Last only", type=input.bool, defval=false)
t = (aftermarket == false) ? time("1440", "0000-1530") : time("1440", "1600-0000") // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
is_first = na(t[1]) and not na(t) or t[1] < t
day_high = float(na)
day_low = float(na)
k = int(na)
if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_low := low
day_low
else
day_high := day_high[1]
day_low := day_low[1]
day_low
if high > day_high and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_high
if low < day_low and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
day_low := low
day_low
// if LastOnly == true
// k := -9999
// else
// k := 0
dailyATR = security(syminfo.tickerid, 'D', atr(14))
plot(day_high, style=plot.style_circles, trackprice=true, offset=-9999, color=color.yellow, linewidth=1)
plot(day_high + dailyATR*atr_factor, style=plot.style_circles, trackprice=true, offset=-9999, color=color.white, linewidth=3)
plot(day_low, style=plot.style_circles, trackprice=true, offset=-9999, color=color.yellow, linewidth=1)
plot(day_low - dailyATR*atr_factor, style=plot.style_circles, trackprice=true, offset=-9999, color=color.white, linewidth=3)