Exchange sessions
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
// © Shuttle_Trader

indicator('Exchange sessions', overlay=true)

// To align the description of input parameters, i use - Unicode Em Space = ' ', Unicode Thin Space = ' ' and Space = ' '

showSS = input.bool(false,' Sydney      ', inline='ss', group='>> EXCHANGE << TIME SESSIONS')
showAS = input.bool(true, ' Asia        ', inline='as', group='>> EXCHANGE << TIME SESSIONS')
showLS = input.bool(false,' London    ',   inline='ls', group='>> EXCHANGE << TIME SESSIONS')
showNS = input.bool(true, ' NewYork   ',   inline='ns', group='>> EXCHANGE << TIME SESSIONS')

sess_SS = input.session('0800-1700:23456', '', inline='ss', group='>> EXCHANGE << TIME SESSIONS')
sess_AS = input.session('0800-1700:23456', '', inline='as', group='>> EXCHANGE << TIME SESSIONS')
sess_LS = input.session('0900-1800:23456', '', inline='ls', group='>> EXCHANGE << TIME SESSIONS')
sess_NS = input.session('0900-1700:23456', '', inline='ns', group='>> EXCHANGE << TIME SESSIONS')

colorSS = input.color(color.new(color.green,80), '', inline='ss', group='>> EXCHANGE << TIME SESSIONS')
colorAS = input.color(color.new(color.orange,80),'', inline='as', group='>> EXCHANGE << TIME SESSIONS')
colorLS = input.color(color.new(color.blue,80),  '', inline='ls', group='>> EXCHANGE << TIME SESSIONS')
colorNS = input.color(color.new(color.red,80),   '', inline='ns', group='>> EXCHANGE << TIME SESSIONS')

showSSopen = input.bool(false, ' Start', inline='ss', group='>> EXCHANGE << TIME SESSIONS')
showASopen = input.bool(false, ' Start', inline='as', group='>> EXCHANGE << TIME SESSIONS')
showLSopen = input.bool(false, ' Start', inline='ls', group='>> EXCHANGE << TIME SESSIONS')
showNSopen = input.bool(false, ' Start', inline='ns', group='>> EXCHANGE << TIME SESSIONS')

// To link the given session time to the time zone, I use the name of the time zone from the IANA time zone database.
ss =   time(timeframe.period, sess_SS, 'Australia/Sydney')
asia = time(timeframe.period, sess_AS, 'Asia/Hong_Kong')
ls =   time(timeframe.period, sess_LS, 'Europe/London')
ns =   time(timeframe.period, sess_NS, 'America/New_York')

SS   = na(ss)   ? na : colorSS
Asia = na(asia) ? na : colorAS
LS   = na(ls)   ? na : colorLS
NY   = na(ns)   ? na : colorNS

bgcolor(showSS and timeframe.isintraday ? SS   : na, title='Sydney')
bgcolor(showAS and timeframe.isintraday ? Asia : na, title='Asia')
bgcolor(showLS and timeframe.isintraday ? LS   : na, title='London')
bgcolor(showNS and timeframe.isintraday ? NY   : na, title='New York')

SSstart = na(ss)[1] and ss
bgcolor(color = showSSopen and SSstart and timeframe.isintraday ? color.new(color.yellow,40) : na, title='Show start Sydney session')
ASstart = na(asia)[1] and asia
bgcolor(color = showASopen and ASstart and timeframe.isintraday ? color.new(color.yellow,40) : na, title='Show start Asia session')
LSstart = na(ls)[1] and ls
bgcolor(color = showLSopen and LSstart and timeframe.isintraday ? color.new(color.yellow,40) : na, title='Show start London session')
NSstart = na(ns)[1] and ns
bgcolor(color = showNSopen and NSstart and timeframe.isintraday ? color.new(color.yellow,40) : na, title='Show start New-York session')
