PROTECTED SOURCE SCRIPT

Session Boxes With Vol

49
//version=5
indicator("Session Boxes with Small Black Markers (IST)", overlay=true)

// --------------------
// Session times (IST)
// --------------------
asianStart = 0530
asianEnd = 1130

londonStart = 1230
londonEnd = 1330

nyStart = 1830
nyEnd = 1930

// --------------------
// Helpers: current bar time in IST (hhmm)
// --------------------
sessHour = hour(time, "GMT+5:30")
sessMinute = minute(time, "GMT+5:30")
sessTime = sessHour * 100 + sessMinute

inSession(startT, endT) =>
sessTime >= startT and sessTime < endT

// --------------------
// Colors
// --------------------
asiaFill = color.new(color.rgb(173, 216, 230), 81) // light blue
greyFill = color.new(color.rgb(184, 184, 184), 81) // grey

// --------------------
// Persistent variables
// --------------------
var box asiaBox = na
var label asiaLbl = na
var box londonBox = na
var box nyBox = na

// --------------------
// Utility: small vertical marker (5% of chart height)
// --------------------
createMarker() =>
rng = high - low
off = rng * 0.05
line.new(x1 = bar_index, y1 = low - off, x2 = bar_index, y2 = low + off,
xloc = xloc.bar_index, color = color.black, width = 2)

// --------------------
// Asia session
// --------------------
if inSession(asianStart, asianEnd)
if na(asiaBox)
asiaBox := box.new(left = bar_index, right = bar_index, top = high, bottom = low,
bgcolor = asiaFill, border_width = 0)
asiaLbl := label.new(x = bar_index, y = high, text = "ASIA",
style = label.style_label_left, textcolor = color.black,
color = na, size = size.normal)
createMarker() // start marker
else
box.set_right(asiaBox, bar_index)
box.set_top(asiaBox, math.max(box.get_top(asiaBox), high))
box.set_bottom(asiaBox, math.min(box.get_bottom(asiaBox), low))
label.set_x(asiaLbl, bar_index)
label.set_y(asiaLbl, box.get_top(asiaBox))
else
if not na(asiaBox)
createMarker() // end marker
asiaBox := na
asiaLbl := na

// --------------------
// London session
// --------------------
if inSession(londonStart, londonEnd)
if na(londonBox)
londonBox := box.new(left = bar_index, right = bar_index, top = high, bottom = low,
bgcolor = greyFill, border_width = 0)
createMarker() // start marker
else
box.set_right(londonBox, bar_index)
box.set_top(londonBox, math.max(box.get_top(londonBox), high))
box.set_bottom(londonBox, math.min(box.get_bottom(londonBox), low))
else
if not na(londonBox)
createMarker() // end marker
londonBox := na

// --------------------
// New York session
// --------------------
if inSession(nyStart, nyEnd)
if na(nyBox)
nyBox := box.new(left = bar_index, right = bar_index, top = high, bottom = low,
bgcolor = greyFill, border_width = 0)
createMarker() // start marker
else
box.set_right(nyBox, bar_index)
box.set_top(nyBox, math.max(box.get_top(nyBox), high))
box.set_bottom(nyBox, math.min(box.get_bottom(nyBox), low))
else
if not na(nyBox)
createMarker() // end marker
nyBox := na

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.