One Setup for Life ICT
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © minerlancer

//@version=5
indicator('One Setup for Life ICT' , overlay = true , precision = 0 , max_boxes_count = 500 , max_labels_count = 500 , max_lines_count = 500 , max_bars_back = 500)

max_tf   = input.int(defval = 60  , title = 'Max TF Show '  , inline = '0' , group = 'Input')
max_line = input.int(defval = 500 , title = 'Max Bars Back' , maxval = 500 , inline = '0' , group = 'Input')

Timezone = 'America/New_York' 
DOM = (timeframe.multiplier <= max_tf) and (timeframe.isintraday)

//--------------
//---Function
//--------------
is_newbar(sess) =>
    t = time('D', sess, Timezone)
    na(t[1]) and not na(t) or t[1] < t
is_session(sess) =>
    not na(time('D', sess, Timezone))
//--------------
//---End Function
//--------------

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// Divider Daily and open NY
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//---Input
show_daily= input.bool(defval = true , title = 'Daily' , inline = 'divider' , inline = '0' , group = 'Divider')
col_D     = input.color(defval = color.new(color.gray,85) , title = '' , inline = '0' , group = 'Divider')


//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// One set up for life
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

show_Sess = input.bool(defval = false , title = 'Session  ' , inline = '00'  , group = 'Session One Set Up for Life')
show_Box_Sess = input.bool(defval = true , title = 'Box  ' , inline = '00'  , group = 'Session One Set Up for Life')
show_txt_box  = input.bool(defval = true , title = 'Text Box ' , inline = '00'  , group = 'Session One Set Up for Life')

show_Tody_Lin_Sess = input.bool(defval = false , title = 'Today H/L' , inline = '01'  , group = 'Session One Set Up for Life')

show_txt_Lin_Sess  = input.bool(defval = false , title = 'Text '  , inline = '01'  , group = 'Session One Set Up for Life')
show_price_ses     = input.bool(defval = false , title = 'Price' , inline = '01'  , group = 'Session One Set Up for Life')

show_Prev_Lin_Sess = input.bool(defval = true , title = 'Prev. H/L ' , inline = '02'  , group = 'Session One Set Up for Life')
Show_OND           = input.bool(defval = false  , title = 'Show Only for Today' , inline = '02'  , group = 'Session One Set Up for Life')
choise_start_OSFL  = input.string(defval = '09:30' , title = 'Start time when you take Prev.H/L' , options = ['08:30' , '09:30'] , inline = '03'  , group = 'Session One Set Up for Life')
show_line_start    = input.bool(defval = true , title = 'Line Start' , inline = '03'  , group = 'Session One Set Up for Life')
col_line_start     = input.color(defval = color.new(color.orange,60) , title =  '' , inline = '03'  , group = 'Session One Set Up for Life')


show_Sess_0 = input.bool(defval = false , title = 'London' , inline = '0'  , group = 'Session One Set Up for Life')
Sess_0      = '0200-0500'
col_Sess_0  = input.color(defval = color.blue , title = '' , inline = '1'  , group = 'Session One Set Up for Life')
txt_Sess_0  = 'London' 

show_Sess_1 = input.bool(defval = false , title = 'Prev.AM' , inline = '0'  , group = 'Session One Set Up for Life')
Sess_1      = '0930-1200'
col_Sess_1  = input.color(defval = color.red , title = '    ' , inline = '1'  , group = 'Session One Set Up for Life')
txt_Sess_1  = 'Prev.AM' 

show_Sess_2 = input.bool(defval = false , title = 'Lunch' , inline = '0'  , group = 'Session One Set Up for Life')
Sess_2      = '1200-1330'
col_Sess_2  = input.color(defval = color.yellow , title = '    ' , inline = '1'  , group = 'Session One Set Up for Life')
txt_Sess_2  = 'Lunch' 

show_Sess_3 = input.bool(defval = false , title = 'PM' , inline = '0'  , group = 'Session One Set Up for Life')
Sess_3      = '1330-1600'
col_Sess_3  = input.color(defval = color.purple , title = '   ' , inline = '1'  , group = 'Session One Set Up for Life')
txt_Sess_3  = 'PM'

time_start  = choise_start_OSFL == '08:30' ? timestamp(Timezone , year , month , dayofmonth , 8, 30 , 00) : timestamp(Timezone , year , month , dayofmonth , 9, 30 , 00)

// Daily Dividers
is_new_session = time(timeframe.period, '0000-0001', Timezone)
is_line_start  = choise_start_OSFL == '08:30' ? time(timeframe.period, '0830-0831', Timezone) : time(timeframe.period, '0930-0931', Timezone)
var line D_open = na
var line Ny_open = na
if is_new_session and show_daily and DOM
    D_open := line.new(bar_index , bar_index , bar_index , bar_index + 1 , extend = extend.both , color = col_D , style = line.style_solid)
if is_line_start and show_line_start and DOM
    Ny_open := line.new(bar_index , bar_index , bar_index , bar_index + 1 , extend = extend.both , color = col_line_start , style = line.style_dotted)

//--------------
//---Text Box
//--------------
if DOM and show_Sess  
    var float top_bottom = 0
    var color kz_color = na
    var bool in_kz     = na
    var string kz_text = na
    if show_txt_box
        if show_Sess_0 and time(timeframe.period, Sess_0 , Timezone)
            in_kz := true
            kz_color := color.new(col_Sess_0 , 80)
            kz_text := txt_Sess_0 
        else if show_Sess_1 and time(timeframe.period, Sess_1 , Timezone)
            in_kz := true
            kz_color := color.new(col_Sess_1 , 80)
            kz_text := txt_Sess_1 
        else if show_Sess_2 and time(timeframe.period, '1201-1330' , Timezone)
            in_kz := true
            kz_color := color.new(col_Sess_2 , 80)
            kz_text := txt_Sess_2
        else if show_Sess_3 and time(timeframe.period, '1331-1600' , Timezone)
            in_kz := true
            kz_color := color.new(col_Sess_3 , 80)
            kz_text := txt_Sess_3   
        else
            in_kz := false
    else
        in_kz := true

    var box kz_box = na
    var line kz_start_line = na
    var line kz_end_line = na
    if show_txt_box
        if in_kz and not in_kz[1]
            kz_box := box.new(bar_index, high, bar_index, low, border_color = color.new(color.red, 100), bgcolor = kz_color, text = kz_text , text_size = size.small)
            kz_start_line := line.new(bar_index, high, bar_index, box.get_top(kz_box), color = kz_color, style = line.style_dotted)
            top_bottom := 0
        if in_kz[1]
            box.set_right(kz_box, bar_index)
            if high>box.get_bottom(kz_box)
                box.set_bottom(kz_box,1.0010* high)
                box.set_top(kz_box,1.0015*high)
                line.set_y2(kz_start_line, box.get_top(kz_box))
        if in_kz[1] and not in_kz
            kz_end_line := line.new(bar_index, high, bar_index, box.get_top(kz_box), color = kz_color, style = line.style_dotted)
 
//--------------
//---High Low Prev Session
//--------------
if DOM and show_Sess and show_Sess_0 and show_Box_Sess
    var box box_sess_0 = na
    if is_newbar(Sess_0) 
        box_sess_0 := box.new(bar_index, high, bar_index, low , border_color = color.new(#c78234, 100) , bgcolor = color.new(col_Sess_0 , 90))
        if Show_OND  
            box.delete(box_sess_0[1]) 
    else if is_session(Sess_0) 
        box.set_right(box_sess_0, bar_index+1)           
        if high > box.get_top(box_sess_0)
            box.set_top(box_sess_0, high)
        if low < box.get_bottom(box_sess_0)
            box.set_bottom(box_sess_0, low) 
 
    var bool can_draw_high_sess_0 = false
    var bool can_draw_low_sess_0 = false
    var line high_sess_0 = na 
    var line low_sess_0 = na
    var label LBhigh_sess_0 = na
    var label LBlow_sess_0 = na
    if (is_new_session) and show_Sess_0 and show_Prev_Lin_Sess
        can_draw_high_sess_0 := true   
        can_draw_low_sess_0  := true    
        high_sess_0 := line.new(bar_index, box.get_top(box_sess_0), bar_index, box.get_top(box_sess_0), color = col_Sess_0)    // Get new line id
        low_sess_0  := line.new(bar_index, box.get_bottom(box_sess_0), bar_index, box.get_bottom(box_sess_0), color = col_Sess_0)
        if Show_OND
            line.delete(high_sess_0[2])
            line.delete(low_sess_0[2])
        if show_txt_Lin_Sess
            LBhigh_sess_0 := label.new(x = last_bar_index , y = box.get_top(box_sess_0)    , text = show_price_ses ? txt_Sess_0 +' High '+ str.tostring(box.get_top(box_sess_0)) : txt_Sess_0 +' High ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style = label.style_label_down, textcolor = col_Sess_0 , textalign = text.align_right , tooltip = 'Prev.PM High' )
            LBlow_sess_0  := label.new(x = last_bar_index , y = box.get_bottom(box_sess_0) , text = show_price_ses ? txt_Sess_0 +' Low ' +str.tostring(box.get_bottom(box_sess_0)): txt_Sess_0 +' Low ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style =  label.style_label_center, textcolor = col_Sess_0 , textalign = text.align_right , tooltip = 'Prev.PM Low')
            label.delete(LBhigh_sess_0[1]) 
            label.delete(LBlow_sess_0[1])   
    else
        if (can_draw_high_sess_0)
            if (time > (time_start + 0 * 1000*60) and high > line.get_y1(high_sess_0))
                can_draw_high_sess_0 := false  
                label.delete(LBhigh_sess_0[0]) 
            else
                line.set_x2(high_sess_0, bar_index)
        if (can_draw_low_sess_0)
            if (time > (time_start + 0 * 1000*60) and low < line.get_y1(low_sess_0))
                can_draw_low_sess_0 := false
                label.delete(LBlow_sess_0[0])
            else
                line.set_x2(low_sess_0, bar_index)

// _1
if DOM and show_Sess and show_Sess_1 and show_Box_Sess
    var box box_sess_1 = na
    if is_newbar(Sess_1)
        box_sess_1 := box.new(bar_index, high, bar_index, low , border_color = color.new(#c78234, 100), bgcolor = color.new(col_Sess_1 , 90))
        if Show_OND  
            box.delete(box_sess_1[1]) 
    else if is_session(Sess_1) 
        box.set_right(box_sess_1, bar_index+1)                  
        if high > box.get_top(box_sess_1)
            box.set_top(box_sess_1, high)
        if low < box.get_bottom(box_sess_1)
            box.set_bottom(box_sess_1, low) 

    var bool can_draw_high_sess_1 = false
    var bool can_draw_low_sess_1 = false
    var line high_sess_1 = na 
    var line low_sess_1 = na
    var label LBhigh_sess_1 = na
    var label LBlow_sess_1 = na
    if (is_new_session) and show_Sess_1 and show_Prev_Lin_Sess
        can_draw_high_sess_1 := true   
        can_draw_low_sess_1  := true    
        high_sess_1 := line.new(bar_index, box.get_top(box_sess_1), bar_index, box.get_top(box_sess_1), color = col_Sess_1)    // Get new line id
        low_sess_1  := line.new(bar_index, box.get_bottom(box_sess_1), bar_index, box.get_bottom(box_sess_1), color = col_Sess_1)
        if Show_OND
            line.delete(high_sess_1[2])
            line.delete(low_sess_1[2])
        if show_txt_Lin_Sess
            LBhigh_sess_1 := label.new(x = last_bar_index , y = box.get_top(box_sess_1)    , text = show_price_ses ? txt_Sess_1 +' High '+ str.tostring(box.get_top(box_sess_1)) : txt_Sess_1 +' High ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style = label.style_label_down, textcolor = col_Sess_1 , textalign = text.align_right , tooltip = 'Prev.PM High' )
            LBlow_sess_1  := label.new(x = last_bar_index , y = box.get_bottom(box_sess_1) , text = show_price_ses ? txt_Sess_1 +' Low ' +str.tostring(box.get_bottom(box_sess_1)): txt_Sess_1 +' Low ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style =  label.style_label_center, textcolor = col_Sess_1 , textalign = text.align_right , tooltip = 'Prev.PM Low')
            label.delete(LBhigh_sess_1[1]) 
            label.delete(LBlow_sess_1[1])   
    else
        if (can_draw_high_sess_1)
            if (time > (time_start + 0 * 1000*60) and high > line.get_y1(high_sess_1))
                can_draw_high_sess_1 := false  
                label.delete(LBhigh_sess_1[0]) 
            else
                line.set_x2(high_sess_1, bar_index)
        if (can_draw_low_sess_1)
            if (time > (time_start + 0 * 1000*60) and low < line.get_y1(low_sess_1))
                can_draw_low_sess_1 := false
                label.delete(LBlow_sess_1[0])
            else
                line.set_x2(low_sess_1, bar_index)

// _2
if DOM and show_Sess and show_Sess_2 and show_Box_Sess
    var box box_sess_2 = na
    if is_newbar(Sess_2)
        box_sess_2 := box.new(bar_index, high, bar_index, low , border_color = color.new(#c78234, 100) , bgcolor = color.new(col_Sess_2 , 90))
        if Show_OND  
            box.delete(box_sess_2[1]) 
    else if is_session(Sess_2) 
        box.set_right(box_sess_2, bar_index+1)           
        if high > box.get_top(box_sess_2)
            box.set_top(box_sess_2, high)
        if low < box.get_bottom(box_sess_2)
            box.set_bottom(box_sess_2, low) 

    var bool can_draw_high_sess_2 = false
    var bool can_draw_low_sess_2 = false
    var line high_sess_2 = na 
    var line low_sess_2 = na
    var label LBhigh_sess_2 = na
    var label LBlow_sess_2 = na
    if (is_new_session) and show_Sess_2 and show_Prev_Lin_Sess
        can_draw_high_sess_2 := true   
        can_draw_low_sess_2  := true    
        high_sess_2 := line.new(bar_index, box.get_top(box_sess_2), bar_index, box.get_top(box_sess_2), color = col_Sess_2)    // Get new line id
        low_sess_2  := line.new(bar_index, box.get_bottom(box_sess_2), bar_index, box.get_bottom(box_sess_2), color = col_Sess_2)
        if Show_OND
            line.delete(high_sess_2[2])
            line.delete(low_sess_2[2])
        if show_txt_Lin_Sess
            LBhigh_sess_2 := label.new(x = last_bar_index , y = box.get_top(box_sess_2)    , text = show_price_ses ? txt_Sess_2 +' High '+ str.tostring(box.get_top(box_sess_2)) : txt_Sess_2 +' High ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style = label.style_label_down, textcolor = col_Sess_2 , textalign = text.align_right , tooltip = 'Prev.PM High' )
            LBlow_sess_2  := label.new(x = last_bar_index , y = box.get_bottom(box_sess_2) , text = show_price_ses ? txt_Sess_2 +' Low ' +str.tostring(box.get_bottom(box_sess_2)): txt_Sess_2 +' Low ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style =  label.style_label_center, textcolor = col_Sess_2 , textalign = text.align_right , tooltip = 'Prev.PM Low')
            label.delete(LBhigh_sess_2[1]) 
            label.delete(LBlow_sess_2[1])   
    else
        if (can_draw_high_sess_2)
            if (time > (time_start + 0 * 1000*60) and high > line.get_y1(high_sess_2))
                can_draw_high_sess_2 := false  
                label.delete(LBhigh_sess_2[0]) 
            else
                line.set_x2(high_sess_2, bar_index)
        if (can_draw_low_sess_2)
            if (time > (time_start + 0 * 1000*60) and low < line.get_y1(low_sess_2))
                can_draw_low_sess_2 := false
                label.delete(LBlow_sess_2[0])
            else
                line.set_x2(low_sess_2, bar_index)

// -3
if DOM and show_Sess and show_Sess_3 and show_Box_Sess
    var box box_sess_3 = na
    if is_newbar(Sess_3) 
        box_sess_3 := box.new(bar_index, high, bar_index, low , border_color = color.new(#c78234, 100), bgcolor = color.new(col_Sess_3 , 90))
        if Show_OND  
            box.delete(box_sess_3[2]) 
    else if is_session(Sess_3) 
        box.set_right(box_sess_3, bar_index+1)           
        if high > box.get_top(box_sess_3)
            box.set_top(box_sess_3, high)
        if low < box.get_bottom(box_sess_3)
            box.set_bottom(box_sess_3, low) 

    var bool can_draw_high_sess_3 = false
    var bool can_draw_low_sess_3 = false
    var line high_sess_3 = na 
    var line low_sess_3 = na
    var label LBhigh_sess_3 = na
    var label LBlow_sess_3 = na
    if (is_new_session) and show_Sess_3 and show_Prev_Lin_Sess
        can_draw_high_sess_3 := true   
        can_draw_low_sess_3  := true    
        high_sess_3 := line.new(bar_index, box.get_top(box_sess_3), bar_index, box.get_top(box_sess_3), color = col_Sess_3)    // Get new line id
        low_sess_3  := line.new(bar_index, box.get_bottom(box_sess_3), bar_index, box.get_bottom(box_sess_3), color = col_Sess_3)
        if Show_OND
            line.delete(high_sess_3[3])
            line.delete(low_sess_3[3])
        if show_txt_Lin_Sess
            LBhigh_sess_3 := label.new(x = last_bar_index , y = box.get_top(box_sess_3)    , text = show_price_ses ? txt_Sess_3 +' High '+ str.tostring(box.get_top(box_sess_3)) : txt_Sess_3 +' High ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style = label.style_label_down, textcolor = col_Sess_3 , textalign = text.align_right , tooltip = 'Prev.PM High' )
            LBlow_sess_3  := label.new(x = last_bar_index , y = box.get_bottom(box_sess_3) , text = show_price_ses ? txt_Sess_3 +' Low ' +str.tostring(box.get_bottom(box_sess_3)): txt_Sess_3 +' Low ', xloc = xloc.bar_index , yloc = yloc.price , color = na , style =  label.style_label_center, textcolor = col_Sess_3 , textalign = text.align_right , tooltip = 'Prev.PM Low')
            label.delete(LBhigh_sess_3[1]) 
            label.delete(LBlow_sess_3[1])   
    else
        if (can_draw_high_sess_3)
            if (time > (time_start + 0 * 1000*60) and high > line.get_y1(high_sess_3))
                can_draw_high_sess_3 := false  
                label.delete(LBhigh_sess_3[0]) 
            else
                line.set_x2(high_sess_3, bar_index)
        if (can_draw_low_sess_3)
            if (time > (time_start + 0 * 1000*60) and low < line.get_y1(low_sess_3))
                can_draw_low_sess_3 := false
                label.delete(LBlow_sess_3[0])
            else
                line.set_x2(low_sess_3, bar_index)





//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// Today H/L + Taken
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//Sessions
//---Ln
sess_today_LN = time(timeframe.period , Sess_0 , Timezone)
var float h_ses_LN = na
var float l_ses_LN = na 
var line line_H_LN = na
var line line_L_LN = na
var label labe_H_LN = na 
var label labe_L_LN = na 
var float line_H_LN_value = na
var float line_L_LN_value = na
var float labe_L_LN_value = na
if sess_today_LN
    if high >= nz(h_ses_LN, 0)
        h_ses_LN := high
    else
        h_ses_LN := h_ses_LN

    if low <= nz(l_ses_LN, high)
        l_ses_LN := low
    else
        l_ses_LN := l_ses_LN
else
    h_ses_LN := na
    l_ses_LN := na
start_H_LN = ta.valuewhen(na(h_ses_LN[1]) and h_ses_LN, bar_index, 0)
start_L_LN = ta.valuewhen(na(l_ses_LN[1]) and l_ses_LN, bar_index, 0)

//---pre_AM
sess_today_pre_AM = time(timeframe.period , Sess_1 , Timezone)
var float h_ses_prev_AM = na
var float l_ses_prev_AM = na 
var line line_H_prev_AM = na
var line line_L_prev_AM = na
var float line_H_prev_AM_value = na 
var float line_L_prev_AM_value = na
if sess_today_pre_AM
    if high >= nz(h_ses_prev_AM, 0)
        h_ses_prev_AM := high
    else
        h_ses_prev_AM := h_ses_prev_AM

    if low <= nz(l_ses_prev_AM, high)
        l_ses_prev_AM := low
    else
        l_ses_prev_AM := l_ses_prev_AM
else
    h_ses_prev_AM := na
    l_ses_prev_AM := na
start_H_prev_AM = ta.valuewhen(na(h_ses_prev_AM[1]) and h_ses_prev_AM, bar_index, 0)
start_L_prev_AM = ta.valuewhen(na(l_ses_prev_AM[1]) and l_ses_prev_AM, bar_index, 0)

//---Lunch
sess_today_Lunch = time(timeframe.period , Sess_2 , Timezone)
var float h_ses_LC = na
var float l_ses_LC = na 
var line line_H_LC = na
var line line_L_LC = na
var float line_H_LC_value = na 
var float line_L_LC_value = na
if sess_today_Lunch
    if high >= nz(h_ses_LC, 0)
        h_ses_LC := high
    else
        h_ses_LC := h_ses_LC

    if low <= nz(l_ses_LC, high)
        l_ses_LC := low
    else
        l_ses_LC := l_ses_LC
else
    h_ses_LC := na
    l_ses_LC := na
start_H_LC = ta.valuewhen(na(h_ses_LC[1]) and h_ses_LC, bar_index, 0)
start_L_LC = ta.valuewhen(na(l_ses_LC[1]) and l_ses_LC, bar_index, 0)

//---PM
sess_today_PM = time(timeframe.period , Sess_3 , Timezone)
var float h_ses_PM = na
var float l_ses_PM = na 
var line line_H_PM = na
var line line_L_PM = na
var float line_H_PM_value = na 
var float line_L_PM_value = na
if sess_today_PM
    if high >= nz(h_ses_PM, 0)
        h_ses_PM := high
    else
        h_ses_PM := h_ses_PM

    if low <= nz(l_ses_PM, high)
        l_ses_PM := low
    else
        l_ses_PM := l_ses_PM
else
    h_ses_PM := na
    l_ses_PM := na
start_H_PM = ta.valuewhen(na(h_ses_PM[1]) and h_ses_PM, bar_index, 0)
start_L_PM = ta.valuewhen(na(l_ses_PM[1]) and l_ses_PM, bar_index, 0)

//---Plot H/L lines
//---LN to NY
if show_Tody_Lin_Sess and DOM
    if sess_today_LN and show_Sess_0
        line_H_LN_value := h_ses_LN
        line_L_LN_value := l_ses_LN
    if sess_today_pre_AM
        line_H_prev_AM_value := h_ses_prev_AM
        line_L_prev_AM_value := l_ses_prev_AM
    if sess_today_Lunch
        line_H_LC_value := h_ses_LC
        line_L_LC_value := l_ses_LC
    if sess_today_PM
        line_H_PM_value := h_ses_PM
        line_L_PM_value := l_ses_PM

isToday = dayofweek(time) == dayofweek(timenow) 

sess_to = time(timeframe.period , '0500-0930' , Timezone)
take_col_H_LN = line_H_prev_AM_value > line_H_LN_value
take_col_L_LN = line_L_prev_AM_value < line_L_LN_value
col_H_LN = take_col_H_LN ? col_Sess_0 : na
col_L_LN = take_col_L_LN ? col_Sess_0 : na
plot(isToday and show_Sess and show_Tody_Lin_Sess and DOM and sess_to ? line_H_LN_value : na  , '' , col_H_LN , 1 , plot.style_steplinebr) , plot(isToday and show_Sess and not sess_today_LN and DOM and not take_col_H_LN ? line_H_LN_value : na , '' , col_H_LN , 1 , plot.style_steplinebr)
plot(isToday and show_Sess and show_Tody_Lin_Sess and DOM and sess_to ? line_L_LN_value : na  , '' , col_L_LN , 1 , plot.style_steplinebr) , plot(isToday and show_Sess and not sess_today_LN and DOM and not take_col_L_LN ? line_L_LN_value : na , '' , col_L_LN , 1 , plot.style_steplinebr)

sess_to_prev_AM = time(timeframe.period , '1200-1330' , Timezone)
take_col_H_prev_AM = line_H_PM_value > line_H_prev_AM_value
take_col_L_prev_AM = line_L_PM_value < line_L_prev_AM_value
col_H_prev_AM = take_col_H_prev_AM ? col_Sess_1 : na
col_L_prev_AM = take_col_L_prev_AM ? col_Sess_1 : na
plot(isToday and show_Sess and show_Tody_Lin_Sess and DOM and sess_to_prev_AM ? line_H_prev_AM_value : na  , '' , col_H_prev_AM , 1 , plot.style_steplinebr) , plot(isToday and show_Sess and not sess_to_prev_AM and DOM and not take_col_H_prev_AM ? line_H_prev_AM_value : na , '' , col_H_prev_AM , 1 , plot.style_steplinebr)
plot(isToday and show_Sess and show_Tody_Lin_Sess and DOM and sess_to_prev_AM ? line_L_prev_AM_value : na  , '' , col_L_prev_AM , 1 , plot.style_steplinebr) , plot(isToday and show_Sess and not sess_to_prev_AM and DOM and not take_col_L_prev_AM ? line_L_prev_AM_value : na , '' , col_L_prev_AM , 1 , plot.style_steplinebr)
