OPEN-SOURCE SCRIPT
9:00-9:59 NY Range -> 10:00-11:00 Lines (v6)

//version=6
indicator("9:00-9:59 NY Range -> 10:00-11:00 Lines (v6)", overlay=true, max_lines_count=500)
// --- state vars ---
var float sessionHigh = na
var float sessionLow = na
var line hiLine = na
var line loLine = na
var line v10 = na
var line v11 = na
// --- New York time ---
t_ny = time("America/New_York")
hr = hour(t_ny)
mn = minute(t_ny)
// --- reset / clear at 16:00 (4 PM NY) ---
if hr == 16 and mn == 0
sessionHigh := na
sessionLow := na
if not na(hiLine)
line.delete(hiLine)
hiLine := na
if not na(loLine)
line.delete(loLine)
loLine := na
if not na(v10)
line.delete(v10)
v10 := na
if not na(v11)
line.delete(v11)
v11 := na
// --- accumulate 9:00 - 9:59 NY range ---
if hr == 9
if mn == 0
sessionHigh := high
sessionLow := low
else
sessionHigh := na(sessionHigh) ? high : math.max(sessionHigh, high)
sessionLow := na(sessionLow) ? low : math.min(sessionLow, low)
// --- at 10:00 NY: draw horizontal lines (start) and vertical dashed at 10:00 ---
if hr == 10 and mn == 0
// delete previous day's horizontal lines if any
if not na(hiLine)
line.delete(hiLine)
hiLine := na
if not na(loLine)
line.delete(loLine)
loLine := na
hiLine := line.new(bar_index, sessionHigh, bar_index, sessionHigh, color=color.red, width=1, extend=extend.none)
loLine := line.new(bar_index, sessionLow, bar_index, sessionLow, color=color.red, width=1, extend=extend.none)
if not na(v10)
line.delete(v10)
v10 := na
v10 := line.new(bar_index, low, bar_index, high, color=color.red, width=1, style=line.style_dashed)
// --- at 11:00 NY: draw vertical dashed at 11:00 ---
if hr == 11 and mn == 0
if not na(v11)
line.delete(v11)
v11 := na
v11 := line.new(bar_index, low, bar_index, high, color=color.red, width=1, style=line.style_dashed)
// --- extend the horizontal lines forward every bar, but only until 11:00 ---
if hr < 11
if not na(hiLine)
line.set_x2(hiLine, bar_index)
if not na(loLine)
line.set_x2(loLine, bar_index)
// --- required output so script compiles (hidden) ---
plot(na)
indicator("9:00-9:59 NY Range -> 10:00-11:00 Lines (v6)", overlay=true, max_lines_count=500)
// --- state vars ---
var float sessionHigh = na
var float sessionLow = na
var line hiLine = na
var line loLine = na
var line v10 = na
var line v11 = na
// --- New York time ---
t_ny = time("America/New_York")
hr = hour(t_ny)
mn = minute(t_ny)
// --- reset / clear at 16:00 (4 PM NY) ---
if hr == 16 and mn == 0
sessionHigh := na
sessionLow := na
if not na(hiLine)
line.delete(hiLine)
hiLine := na
if not na(loLine)
line.delete(loLine)
loLine := na
if not na(v10)
line.delete(v10)
v10 := na
if not na(v11)
line.delete(v11)
v11 := na
// --- accumulate 9:00 - 9:59 NY range ---
if hr == 9
if mn == 0
sessionHigh := high
sessionLow := low
else
sessionHigh := na(sessionHigh) ? high : math.max(sessionHigh, high)
sessionLow := na(sessionLow) ? low : math.min(sessionLow, low)
// --- at 10:00 NY: draw horizontal lines (start) and vertical dashed at 10:00 ---
if hr == 10 and mn == 0
// delete previous day's horizontal lines if any
if not na(hiLine)
line.delete(hiLine)
hiLine := na
if not na(loLine)
line.delete(loLine)
loLine := na
hiLine := line.new(bar_index, sessionHigh, bar_index, sessionHigh, color=color.red, width=1, extend=extend.none)
loLine := line.new(bar_index, sessionLow, bar_index, sessionLow, color=color.red, width=1, extend=extend.none)
if not na(v10)
line.delete(v10)
v10 := na
v10 := line.new(bar_index, low, bar_index, high, color=color.red, width=1, style=line.style_dashed)
// --- at 11:00 NY: draw vertical dashed at 11:00 ---
if hr == 11 and mn == 0
if not na(v11)
line.delete(v11)
v11 := na
v11 := line.new(bar_index, low, bar_index, high, color=color.red, width=1, style=line.style_dashed)
// --- extend the horizontal lines forward every bar, but only until 11:00 ---
if hr < 11
if not na(hiLine)
line.set_x2(hiLine, bar_index)
if not na(loLine)
line.set_x2(loLine, bar_index)
// --- required output so script compiles (hidden) ---
plot(na)
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.