Time Zone / Market Sessions
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © traderharikrishna

//@version=5
indicator("Time/Sessions",overlay=true)
/////////////////////////////////////////
showtime=input(true,'Show Time Sessions',group='TIME/SESSION')
var show_newyork_session =  true and showtime
var newyork_color = input(title='New York Session Color', defval=color.rgb(10, 141, 242, 20),group='TIME/SESSION')
var newyork_text_color = input(title='New York Session Label Color', defval=color.rgb(10, 141, 242, 0),group='TIME/SESSION')
var newyork_position = input.string(title='New York Session Position', options=['Top', 'Bottom'], defval='Top',group='TIME/SESSION')

var show_london_session =  true and showtime
var london_color = input(title='London Session Color', defval=color.rgb(80, 204, 27, 20),group='TIME/SESSION')
var london_text_color = input(title='London Session Label Color', defval=color.rgb(80, 204, 27, 0),group='TIME/SESSION')
var london_position = input.string(title='London Session Position', options=['Top', 'Bottom'], defval='Bottom',group='TIME/SESSION')

var show_tokyo_session = true and showtime
var tokyo_color = input(title='Tokyo Session Color', defval=color.rgb(252, 223, 3, 20),group='TIME/SESSION')
var tokyo_text_color = input(title='Tokyo Session Label Color', defval=color.rgb(252, 223, 3, 0),group='TIME/SESSION')
var tokyo_position = input.string(title='Tokyo Session Position', options=['Top', 'Bottom'], defval='Top',group='TIME/SESSION')

var show_sydney_session = true and showtime
var sydney_color = input(title='Sydney Session Color', defval=color.rgb(247, 72, 238, 20),group='TIME/SESSION')
var sydney_text_color = input(title='Sydney Session Label Color', defval=color.rgb(253, 75, 215),group='TIME/SESSION')
var sydney_position = input.string(title='Sydney Session Position', options=['Top', 'Bottom'], defval='Bottom',group='TIME/SESSION')

// sessions
newyork_session = time(timeframe.period, '0800-1600:1234567', 'America/New_York')
newyork_session_start = time(timeframe.period, '0800-0801:1234567', 'America/New_York')

plotshape(show_newyork_session ? newyork_session : na, style=shape.square, color=newyork_color, location=newyork_position == 'Top' ? location.top : location.bottom, size=size.auto)
plotshape(show_newyork_session ? newyork_session_start : na, style=shape.square, color=color.rgb(255, 255, 255, 255), textcolor=newyork_text_color, location=newyork_position == 'Top' ? location.top : location.bottom, size=size.auto, text='Newyork')

london_session = time(timeframe.period, '0300-1100:1234567', 'America/New_York')
london_session_start = time(timeframe.period, '0300-0301:1234567', 'America/New_York')
plotshape(show_london_session ? london_session : na, style=shape.square, color=london_color, location=london_position == 'Top' ? location.top : location.bottom, size=size.auto)
plotshape(show_london_session ? london_session_start : na, style=shape.square, color=color.rgb(0, 0, 0, 255), textcolor=london_text_color, location=london_position == 'Top' ? location.top : location.bottom, size=size.auto, text='London')

tokyo_session = time(timeframe.period, '1900-0300:1234567', 'America/New_York')
tokyo_session_start = time(timeframe.period, '1900-1901:1234567', 'America/New_York')
plotshape(show_tokyo_session ? tokyo_session : na, style=shape.square, color=tokyo_color, location=tokyo_position == 'Top' ? location.top : location.bottom, size=size.auto)
plotshape(show_tokyo_session ? tokyo_session_start : na, style=shape.square, color=color.rgb(0, 0, 0, 255), textcolor=tokyo_text_color, location=tokyo_position == 'Top' ? location.top : location.bottom, size=size.auto, text='Tokyo')

sydney_session = time(timeframe.period, '1700-0100:1234567', 'America/New_York')
sydney_session_start = time(timeframe.period, '1700-1701:1234567', 'America/New_York')
plotshape(show_sydney_session ? sydney_session : na, style=shape.square, color=sydney_color, location=sydney_position == 'Top' ? location.top : location.bottom, size=size.auto)
plotshape(show_sydney_session ? sydney_session_start : na, style=shape.square, color=color.rgb(0, 0, 0, 255), textcolor=sydney_text_color, location=sydney_position == 'Top' ? location.top : location.bottom, size=size.auto, text='Sydney')

// alerts
alertcondition(newyork_session_start, title='New York Session Open', message='New York Session Open')
alertcondition(london_session_start, title='London Session Open', message='London Session Open')
alertcondition(tokyo_session_start, title='Tokyo Session Open', message='Tokyo Session Open')
alertcondition(sydney_session_start, title='Sydney Session Open', message='Sydney Session Open')

markets = table.new(position.top_right, 4, 9, border_width=1)

if not showtime
    table.cell(markets, 0, 0, text='OPEN', bgcolor=color.rgb(39, 133, 42),text_color=color.new(#ffffff, 0), text_size=size.small,text_halign=text.align_left)

    table.cell(markets, 0, 1, text='NewYork ' + str.tostring(hour(timenow,"America/New_York"), "00:") + str.tostring(minute(timenow,"America/New_York"), "00:") + str.tostring(second(timenow,"America/New_York"), "00") + "", bgcolor=newyork_session?newyork_color:color.gray,text_color=color.new(#ffffff, 0), text_size=size.small,text_halign=text.align_left)

    table.cell(markets, 0, 2, text='London  '+ str.tostring(hour(timenow,"Europe/London"), "00:") + str.tostring(minute(timenow,"Europe/London"), "00:") + str.tostring(second(timenow,"Europe/London"), "00") + "", bgcolor=london_session?london_color:color.gray, text_color=color.new(#ffffff, 0), text_size=size.small,text_halign=text.align_left)

    table.cell(markets, 0, 3, text='Tokyo     '+ str.tostring(hour(timenow,"Asia/Tokyo"), "00:") + str.tostring(minute(timenow,"Asia/Tokyo"), "00:") + str.tostring(second(timenow,"Asia/Tokyo"), "00") + "", bgcolor=tokyo_session?tokyo_color:color.gray,text_color=color.new(#ffffff, 0), text_size=size.small,text_halign=text.align_left)

    table.cell(markets, 0, 4, text='Sydney   '+ str.tostring(hour(timenow,"Australia/Sydney"), "00:") + str.tostring(minute(timenow,"Australia/Sydney"), "00:") + str.tostring(second(timenow,"Australia/Sydney"), "00") + "", bgcolor= sydney_session?sydney_color:color.gray, text_color=color.new(#ffffff, 0), text_size=size.small,text_halign=text.align_left)

