OPEN-SOURCE SCRIPT

Session Boxes

193
//version=6
indicator("Session Boxes", overlay=true)

// Sessions Definitionen
tokyo_start = timestamp(year(time), month(time), dayofmonth(time), 0, 0)
tokyo_end = timestamp(year(time), month(time), dayofmonth(time), 9, 0)
london_start = timestamp(year(time), month(time), dayofmonth(time), 7, 0)
london_end = timestamp(year(time), month(time), dayofmonth(time), 16, 0)
newyork_start = timestamp(year(time), month(time), dayofmonth(time), 12, 0)
newyork_end = timestamp(year(time), month(time), dayofmonth(time), 21, 0)

// Farben (dezent)
color_tokyo = color.rgb(204, 204, 204, 50)
color_london = color.rgb(170, 170, 170, 50)
color_newyork = color.rgb(136, 136, 136, 50)

// Funktion zum Zeichnen der Session-Boxen
sessionBox(startTime, endTime, sessionColor) =>
var int startIndex = na
var int endIndex = na
var float sessionHigh = na
var float sessionLow = na

isSession = (time >= startTime and time <= endTime)

if isSession
if na(startIndex)
startIndex := bar_index
sessionHigh := high
sessionLow := low
endIndex := bar_index
sessionHigh := math.max(sessionHigh, high)
sessionLow := math.min(sessionLow, low)

if not na(startIndex) and not na(endIndex)
box.new(left=int(startIndex), right=int(endIndex), top=sessionHigh, bottom=sessionLow, bgcolor=sessionColor, border_color=sessionColor)

// Sessions auf dem Chart zeichnen
sessionBox(tokyo_start, tokyo_end, color_tokyo)
sessionBox(london_start, london_end, color_london)
sessionBox(newyork_start, newyork_end, color_newyork)

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.