//@version=6 indicator("Trading Sessions (NY Time - 10 Sessions)", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500) bool showSessionNames = input.bool(true, "Show session names") bool showSessionOC = input.bool(true, "Draw session open and close lines") bool showSessionTickRange = input.bool(true, "Show tick range for each session") bool showSessionAverage = input.bool(true, "Show average price per session") // Fixed New York Timezone for all sessions const string NY_TIMEZONE = "America/New_York" // Session 1 const string SESSION_1_GROUP = "Session 1" showSession1 = input.bool(true, "Show session", group = SESSION_1_GROUP) session1Name = input.string("Session 1", "Displayed name", group = SESSION_1_GROUP, active = showSession1) session1Time = input.session("0930-1130", "Session time (NY Time)", group = SESSION_1_GROUP, active = showSession1) session1Color = input.color(color.new(#2962FF, 85), "Session color", group = SESSION_1_GROUP, active = showSession1) // Session 2 const string SESSION_2_GROUP = "Session 2" showSession2 = input.bool(true, "Show session", group = SESSION_2_GROUP) session2Name = input.string("Session 2", "Displayed name", group = SESSION_2_GROUP, active = showSession2) session2Time = input.session("1130-1330", "Session time (NY Time)", group = SESSION_2_GROUP, active = showSession2) session2Color = input.color(color.new(#FF9800, 85), "Session color", group = SESSION_2_GROUP, active = showSession2) // Session 3 const string SESSION_3_GROUP = "Session 3" showSession3 = input.bool(true, "Show session", group = SESSION_3_GROUP) session3Name = input.string("Session 3", "Displayed name", group = SESSION_3_GROUP, active = showSession3) session3Time = input.session("1330-1530", "Session time (NY Time)", group = SESSION_3_GROUP, active = showSession3) session3Color = input.color(color.new(#089981, 85), "Session color", group = SESSION_3_GROUP, active = showSession3) // Session 4 const string SESSION_4_GROUP = "Session 4" showSession4 = input.bool(false, "Show session", group = SESSION_4_GROUP) session4Name = input.string("Session 4", "Displayed name", group = SESSION_4_GROUP, active = showSession4) session4Time = input.session("1530-1700", "Session time (NY Time)", group = SESSION_4_GROUP, active = showSession4) session4Color = input.color(color.new(#9C27B0, 85), "Session color", group = SESSION_4_GROUP, active = showSession4) // Session 5 const string SESSION_5_GROUP = "Session 5" showSession5 = input.bool(false, "Show session", group = SESSION_5_GROUP) session5Name = input.string("Session 5", "Displayed name", group = SESSION_5_GROUP, active = showSession5) session5Time = input.session("0200-0500", "Session time (NY Time)", group = SESSION_5_GROUP, active = showSession5) session5Color = input.color(color.new(#E91E63, 85), "Session color", group = SESSION_5_GROUP, active = showSession5) // Session 6 const string SESSION_6_GROUP = "Session 6" showSession6 = input.bool(false, "Show session", group = SESSION_6_GROUP) session6Name = input.string("Session 6", "Displayed name", group = SESSION_6_GROUP, active = showSession6) session6Time = input.session("1900-2200", "Session time (NY Time)", group = SESSION_6_GROUP, active = showSession6) session6Color = input.color(color.new(#00BCD4, 85), "Session color", group = SESSION_6_GROUP, active = showSession6) // Session 7 const string SESSION_7_GROUP = "Session 7" showSession7 = input.bool(false, "Show session", group = SESSION_7_GROUP) session7Name = input.string("Session 7", "Displayed name", group = SESSION_7_GROUP, active = showSession7) session7Time = input.session("2200-0100", "Session time (NY Time)", group = SESSION_7_GROUP, active = showSession7) session7Color = input.color(color.new(#FF5722, 85), "Session color", group = SESSION_7_GROUP, active = showSession7) // Session 8 const string SESSION_8_GROUP = "Session 8" showSession8 = input.bool(false, "Show session", group = SESSION_8_GROUP) session8Name = input.string("Session 8", "Displayed name", group = SESSION_8_GROUP, active = showSession8) session8Time = input.session("0100-0400", "Session time (NY Time)", group = SESSION_8_GROUP, active = showSession8) session8Color = input.color(color.new(#795548, 85), "Session color", group = SESSION_8_GROUP, active = showSession8) // Session 9 const string SESSION_9_GROUP = "Session 9" showSession9 = input.bool(false, "Show session", group = SESSION_9_GROUP) session9Name = input.string("Session 9", "Displayed name", group = SESSION_9_GROUP, active = showSession9) session9Time = input.session("0400-0700", "Session time (NY Time)", group = SESSION_9_GROUP, active = showSession9) session9Color = input.color(color.new(#607D8B, 85), "Session color", group = SESSION_9_GROUP, active = showSession9) // Session 10 const string SESSION_10_GROUP = "Session 10" showSession10 = input.bool(false, "Show session", group = SESSION_10_GROUP) session10Name = input.string("Session 10", "Displayed name", group = SESSION_10_GROUP, active = showSession10) session10Time = input.session("0700-0930", "Session time (NY Time)", group = SESSION_10_GROUP, active = showSession10) session10Color = input.color(color.new(#3F51B5, 85), "Session color", group = SESSION_10_GROUP, active = showSession10) type SessionDisplay box sessionBox label sessionLabel line openLine line avgLine line closeLine float sumClose int numOfBars type SessionInfo color color string name string session SessionDisplay active = na method setName(SessionDisplay this, string name) => sessionLabel = this.sessionLabel sessionBox = this.sessionBox boxText = array.new() if showSessionTickRange boxText.push("Range: " + str.tostring((sessionBox.get_top() - sessionBox.get_bottom()) / syminfo.mintick, format.mintick)) if showSessionAverage boxText.push("Avg: " + str.tostring(this.sumClose / this.numOfBars, format.mintick)) if showSessionNames boxText.push(name) sessionLabel.set_y(sessionBox.get_bottom()) sessionLabel.set_text(array.join(boxText, "\n")) method createSessionDisplay(SessionInfo this) => boxColor = this.color opaqueColor = color.new(boxColor, 0) dis = SessionDisplay.new( sessionBox = box.new(bar_index, high, bar_index, low, bgcolor = boxColor, border_color = na), sessionLabel = label.new(bar_index, low, "", style = label.style_label_upper_left, textalign = text.align_left, textcolor = opaqueColor, color = color(na)), openLine = showSessionOC ? line.new(bar_index, open, bar_index, open, color = opaqueColor, style = line.style_dashed, width = 1) : na, closeLine = showSessionOC ? line.new(bar_index, close, bar_index, close, color = opaqueColor, style = line.style_dashed, width = 1) : na, avgLine = showSessionAverage ? line.new(bar_index, close, bar_index, close, style = line.style_dotted, width = 2, color = opaqueColor) : na, sumClose = close, numOfBars = 1 ) if showSessionOC and not na(dis.openLine) and not na(dis.closeLine) linefill.new(dis.openLine, dis.closeLine, boxColor) dis.setName(this.name) this.active := dis method updateSessionDisplay(SessionInfo this) => sessionDisp = this.active sessionBox = sessionDisp.sessionBox openLine = sessionDisp.openLine closeLine = sessionDisp.closeLine avgLine = sessionDisp.avgLine sessionDisp.sumClose += close sessionDisp.numOfBars += 1 sessionBox.set_top(math.max(sessionBox.get_top(), high)) sessionBox.set_bottom(math.min(sessionBox.get_bottom(), low)) sessionBox.set_right(bar_index) sessionDisp.setName(this.name) if showSessionOC and not na(openLine) and not na(closeLine) openLine.set_x2(bar_index) closeLine.set_x2(bar_index) closeLine.set_y1(close) closeLine.set_y2(close) if showSessionAverage and not na(avgLine) avgLine.set_x2(bar_index) avg = sessionDisp.sumClose / sessionDisp.numOfBars avgLine.set_y1(avg) avgLine.set_y2(avg) sessionDisp method update(SessionInfo this) => bool isChange = timeframe.change("1D") // Use fixed NY timezone for all sessions if (not na(time("", this.session, NY_TIMEZONE))) // inSession based on NY time if na(this.active) or isChange this.createSessionDisplay() else this.updateSessionDisplay() else if not na(this.active) this.active := na getSessionInfos()=> array sessionInfos = array.new() if showSession1 sessionInfos.push(SessionInfo.new(session1Color, session1Name, session1Time)) if showSession2 sessionInfos.push(SessionInfo.new(session2Color, session2Name, session2Time)) if showSession3 sessionInfos.push(SessionInfo.new(session3Color, session3Name, session3Time)) if showSession4 sessionInfos.push(SessionInfo.new(session4Color, session4Name, session4Time)) if showSession5 sessionInfos.push(SessionInfo.new(session5Color, session5Name, session5Time)) if showSession6 sessionInfos.push(SessionInfo.new(session6Color, session6Name, session6Time)) if showSession7 sessionInfos.push(SessionInfo.new(session7Color, session7Name, session7Time)) if showSession8 sessionInfos.push(SessionInfo.new(session8Color, session8Name, session8Time)) if showSession9 sessionInfos.push(SessionInfo.new(session9Color, session9Name, session9Time)) if showSession10 sessionInfos.push(SessionInfo.new(session10Color, session10Name, session10Time)) sessionInfos var array sessionInfos = getSessionInfos() if timeframe.isdwm runtime.error("This indicator can only be used on intraday timeframes.") for info in sessionInfos info.update()