//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
indicator('Open Lines', overlay=true, max_bars_back=500)
var grp1 = 'Show - Hour - Minute - Label Text - Color'
TOOLTIP01 = "Enter your time zone's offset (+ or -). Eg. +5 / -3 / +9:30"
hoursOffsetInput = input.string('-4', "Timezone offset (GMT)", tooltip = TOOLTIP01)
TIMEZONE = "GMT"+hoursOffsetInput
sess1Show = input.bool(true, title='', inline='1', group=grp1)
sess1Hour = input.int(17, title='', minval=0, maxval=23, inline='1', group=grp1)
sess1Minute = input.int(0, title='', minval=0, maxval=60, inline='1', group=grp1)
sess1Text = input.string("Session Open ", title='', inline='1', group=grp1)
sess1Col = input.color(color.red, title='', inline="1", group=grp1)
inSession1 = hour == sess1Hour and minute == sess1Minute and second == 0
sess2Show = input.bool(false, title='', inline='2', group=grp1)
sess2Hour = input.int(0, title='', minval=0, maxval=23, inline='2', group=grp1)
sess2Minute = input.int(0, title='', minval=0, maxval=60, inline='2', group=grp1)
sess2Text = input.string("Day Open ", title='', inline='2', group=grp1)
sess2Col = input.color(color.green, title='', inline="2", group=grp1)
inSession2 = hour == sess2Hour and minute == sess2Minute and second == 0
sess3Show = input.bool(false, title='', inline='3', group=grp1)
sess3Hour = input.int(2, title='', minval=0, maxval=23, inline='3', group=grp1)
sess3Minute = input.int(0, title='', minval=0, maxval=60, inline='3', group=grp1)
sess3Text = input.string("London Open ", title='', inline='3', group=grp1)
sess3Col = input.color(color.blue, title='', inline="3", group=grp1)
inSession3 = hour == sess3Hour and minute == sess3Minute and second == 0
var grp2 = 'Other Settings'
MAX_LINES = input.int(10, title='Max Lines to show', minval=0, maxval=200, group=grp2)
extendHours = input.int(24, title='Extend lines for how many hours?', minval=1, maxval=24, group=grp2)
linesWidth = input.int(1, title='Lines Width', minval=1, maxval=4, group=grp2)
_labelSize = input.string("Tiny", title='Label Size', options=['Auto', 'Tiny', 'Small', 'Normal', 'Huge'], group=grp2)
labelSize = _labelSize == "auto" ? size.auto : _labelSize == "Tiny" ? size.tiny : _labelSize == "Small" ? size.small : _labelSize == "Normal" ? size.normal : size.huge
var line[] l1 = array.new_line(0)
var line[] l2 = array.new_line(0)
var line[] l3 = array.new_line(0)
var label[] la1 = array.new_label(0)
var label[] la2 = array.new_label(0)
var label[] la3 = array.new_label(0)
_extend = extendHours * 3600000
if inSession1 and not inSession1[1] and sess1Show
array.push(l1, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess1Col, width=linesWidth))
array.push(la1, label.new(time + _extend, open, sess1Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess1Col))
if inSession2 and not inSession2[1] and sess2Show
array.push(l2, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess2Col, width=linesWidth))
array.push(la2, label.new(time + _extend, open, sess2Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess2Col))
if inSession3 and not inSession3[1] and sess3Show
array.push(l3, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess3Col, width=linesWidth))
array.push(la3, label.new(time + _extend, open, sess3Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess3Col))
// Delete lines if more than max
if array.size(l1) > MAX_LINES
line.delete(array.shift(l1))
label.delete(array.shift(la1))
if array.size(l2) > MAX_LINES
line.delete(array.shift(l2))
label.delete(array.shift(la2))
if array.size(l3) > MAX_LINES
line.delete(array.shift(l3))
label.delete(array.shift(la3))