OPEN-SOURCE SCRIPT

NY Sessions Boxes (Live Drawing)

112
//version=5
indicator("NY Sessions Boxes (Live Drawing)", overlay=true)

ny_tz = "America/New_York"
t = time(timeframe.period, ny_tz)
hour_ny = hour(t)
minute_ny = minute(t)

// سشن ۱: 02:00 – 05:00
session1_active = (hour_ny >= 2 and hour_ny < 5)
session1_start = (hour_ny == 2 and minute_ny == 0)

// سشن ۲: 09:30 – 11:00
session2_active = ((hour_ny == 9 and minute_ny >= 30) or (hour_ny > 9 and hour_ny < 11))
session2_start = (hour_ny == 9 and minute_ny == 30)

var box box1 = na
var float hi1 = na
var float lo1 = na

if session1_start
hi1 := high
lo1 := low
box1 := box.new(left = time, right = time, top = high, bottom = low, bgcolor=color.new(color.blue, 85), border_color=color.blue)

if session1_active and not na(box1)
hi1 := math.max(hi1, high)
lo1 := math.min(lo1, low)
box.set_right(box1, time)
box.set_top(box1, hi1)
box.set_bottom(box1, lo1)

if not session1_active and not na(box1)
box1 := na
hi1 := na
lo1 := na

var box box2 = na
var float hi2 = na
var float lo2 = na

if session2_start
hi2 := high
lo2 := low
box2 := box.new(left = time, right = time, top = high, bottom = low, bgcolor=color.new(color.purple, 85), border_color=color.purple)

if session2_active and not na(box2)
hi2 := math.max(hi2, high)
lo2 := math.min(lo2, low)
box.set_right(box2, time)
box.set_top(box2, hi2)
box.set_bottom(box2, lo2)

if not session2_active and not na(box2)
box2 := na
hi2 := na
lo2 := na

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.