ICT TIME & PRICE INDICATOR

//@version=5
indicator(title='Time & Price', overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)

i_tz = input.string("UTC-5", "Time Zone")
i_sess = input.session("0930-1600:23456", "Session")

canvas_col = input.color(color.new(#d1d4dc, 50), "Canvas")
box_col = input.color(color.new(color.black, 0), "Box")
open_col = input.color(color.new(color.red, 20), "Open")
text_col = input.color(color.new(color.black, 0), "Text")

var box sess_box = na
var line open_line = na
var label sess_text = na
var sess_high = 0.0
var sess_low = 0.0

in_sess = not na(time(timeframe.period, i_sess, i_tz)) and timeframe.isintraday
sess_start = in_sess and not in_sess[1]
sess_end = not in_sess and in_sess[1]

barcolor(sess_start ? open_col : na)

if sess_start
    sess_high := high
    sess_low  := low
else if in_sess
    sess_high := math.max(sess_high, high)
    sess_low := math.min(sess_low, low)
    
if sess_start   
    sess_box := box.new(left=bar_index, top=na, right=na, bottom=na, bgcolor=na, border_color=box_col, border_style=line.style_dotted, border_width=1)
    open_line := line.new(bar_index, open, bar_index+1, open, extend=extend.right, color=open_col, style=line.style_solid, width=1)  
    sess_text := label.new(x=bar_index, y=na, style=label.style_label_lower_left, size=size.small, textcolor=text_col, color=canvas_col, text_font_family=font.family_monospace)
    label.set_text(sess_text, str.format_time(time, "HHmm", i_tz))
if sess_end
    box.set_top(sess_box, sess_high)
    box.set_bottom(sess_box, sess_low)
    box.set_right(sess_box, bar_index)
    label.set_y(sess_text, sess_high)
    line.set_extend(open_line, extend.none)
    line.set_x2(open_line, bar_index)