SMC sessionzz by Jelle
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JelleArts
// Last Updated: 19th March 2023
// @version=5
indicator(title="SMC sessionzz by Jelle", shorttitle="SMC sessionzz", overlay=true)

// This indicator helps me to identify key levels in the market by plotting session information on the chart. 
// On the analysis timeframes (1H / 30M) the bars will be coloured according to session times which makes it easy to identify the highs and lows of each session. 
// On the entry timeframes (< 30M) the killzones are highlighted on the background off the chart.
// GMT and NY midnight lines are also added to identify points of interest in the market.

// TIMEFRAME SETTINGS
hideOn240AndAbove1       = input.bool(title="Hide Background and Bar color on 4H and above", defval=true, group = "====== TIMEFRAME SETTINGS ======")
hideTimeframeCB1         = input.bool(title="Hide Background on 30M and above", defval=true, group = "====== TIMEFRAME SETTINGS ======")
hideTimeframeLow         = input.bool(title="Hide Bar Color below 30M", defval=true, group = "====== TIMEFRAME SETTINGS ======")

// Determine whether or not this timeframe is to be ignored for BACKGROUND
hide1 = hideTimeframeCB1 and timeframe.period == "30" or timeframe.period == "60" or timeframe.period == "240" or timeframe.period == "D" or timeframe.period == "W" or timeframe.period == "M"

// Determine whether or not this timeframe is to be ignored for BAR COLOR
hide2 = hideOn240AndAbove1 and timeframe.period == "240" or timeframe.period == "D" or timeframe.period == "W" or timeframe.period == "M"

// Determine whether or not BAR COLOR is ignored for LOWER TIMEFRAMES
hide3 = hideTimeframeLow and timeframe.period == "1" or timeframe.period == "2" or timeframe.period == "3" or timeframe.period == "5" or timeframe.period == "15"

// InSession() determines if a price bar falls inside the specified session
InSession(sess) => na(time(timeframe.period, sess + ":1234567")) == false


//SESSION 1 - LONDON SESSION

// Get user input
timezone1                = input.session(title="Background London Session", defval="0900-1300", group = "====== London Session ======")
timezone1a               = input.session(title="Bar Color London Session", defval="0900-1500", group = "====== London Session ======")
paintBg1                 = input.bool(title="Paint Background", defval=true, group = "====== London Session ======")
blankInsideCandles1      = input.bool(title="Paint Bars", defval=true, group = "====== London Session ======")

// Color the background of each relevant session and/or bar
bgcolor(color=InSession(timezone1) and paintBg1 and not hide1 ? color.new(#5ab0f7, 81) : na, title="London Background Color")
barcolor(color=InSession(timezone1a) and blankInsideCandles1 and not hide2 and not hide3 ? color.rgb(36, 148, 94) : na, title="London Bar Color")


//SESSION 2 - NEW YORK SESSION

// Get user input
timezone2                = input.session(title="Background NY Session", defval="1400-1800", group = "====== New York Session ======")
timezone2a               = input.session(title="Bar Color NY Session ", defval="1500-2300", group = "====== New York Session ======")
paintBg2                 = input.bool(title="Paint Background", defval=true, group = "====== New York Session ======")
blankInsideCandles2      = input.bool(title="Paint Bars", defval=true, group = "====== New York Session ======")

// Color the background of each relevant session and/or bar
bgcolor(color=InSession(timezone2) and paintBg2 and not hide1 ? color.new(#34da98, 88) : na, title="New York Background Color")
barcolor(color=InSession(timezone2a) and blankInsideCandles2 and not hide2 and not hide3 ? color.rgb(208, 60, 105) : na, title="New York Bar Color")


//SESSION 3 - ASIA SESSION

// Get user input
timezone3                = input.session(title="Background Asia Session ", defval="2000-0700", group = "====== Asia Session ======")
timezone3a               = input.session(title="Bar Color Asia Session", defval="2300-0900", group = "====== Asia Session ======")
paintBg3                 = input.bool(title="Paint Background", defval=false, group = "====== Asia Session ======")
blankInsideCandles3      = input.bool(title="Paint Bars", defval=true, group = "====== Asia Session ======")

// Color the background of each relevant session and/or bar
bgcolor(color=InSession(timezone3) and paintBg3 and not hide1 ? color.new(#73c1e8, 75) : na, title="Asia Background Color")
barcolor(color=InSession(timezone3a) and blankInsideCandles3 and not hide2 and not hide3 ? color.rgb(0, 0, 0) : na, title="Asia Bar Color")


//MIDNIGHT LINE SETTINGS

//TOGGLE ON/OFF GMT
dailyopenline            = input.bool(title="Show GMT midnight line on 1H", defval=true, group = "====== MIDNIGHT LINES ======")

// VERTICAL LINE GMT MIDNIGHT
GMTvalue = (input(defval=2, title = "GMT line offset", group = "====== MIDNIGHT LINES ======"))
gmt_plot = false
if hour == GMTvalue and timeframe.period == "60"  and dailyopenline == true
    gmt_plot := true
else
    gmt_plot := false

vline(BarIndex, Color, LineStyle, LineWidth) =>
    line.new(BarIndex, low - ta.tr, BarIndex, high + ta.tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)

if (gmt_plot)
    vline(bar_index[0], color.rgb(56, 1, 166), line.style_dashed, 1)


//TOGGLE ON/OFF NY
newyorkopenline          = input.bool(title="Show NY midnight line on 1H", defval=false, group = "====== MIDNIGHT LINES ======")

// VERTICAL LINE NEW YORK MIDNIGHT 
NYvalue = (input(defval=7, title = "NY line offset", group = "====== MIDNIGHT LINES ======"))
ny_plot = false
if hour == NYvalue and timeframe.period == "60" and newyorkopenline == true
    ny_plot := true
else
    ny_plot := false

if (ny_plot)
    vline(bar_index[0], color.rgb(255, 116, 57), line.style_dashed, 1)

//END