Session backtest tool
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=5
indicator("Session backtest tool", overlay=true, scale=scale.none)

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Background Overlay

show_daysession = input(title='Show Day Session', defval=true)
daysession = input.session(title='Day Session', defval='0700-1400')

show_eveningsession = input(title='Show Evening Session', defval=true)
eveningsession = input.session(title='Evening Session', defval='1600-2000')

daysession_color = color.new(color.green, 86)
eveningsession_color = color.new(color.purple, 86)


is_session(session) =>
    not na(time(timeframe.period, session))

is_daysession = is_session(daysession)
is_eveningsession = is_session(eveningsession)

bgcolor(show_daysession and is_daysession ? daysession_color : na)
bgcolor(show_eveningsession and is_eveningsession ? eveningsession_color : na)

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Days Of The Week

bartimeoffset = time - time[1]

plotchar(dayofweek == dayofweek.monday,    char='M', location=location.bottom, color=color.new(color.green, 0))
plotchar(dayofweek == dayofweek.tuesday,   char='T', location=location.bottom, color=color.new(color.green, 0))
plotchar(dayofweek == dayofweek.wednesday, char='W', location=location.bottom, color=color.new(color.green, 0))
plotchar(dayofweek == dayofweek.thursday,  char='T', location=location.bottom, color=color.new(color.green, 0))
plotchar(dayofweek == dayofweek.friday,    char='F', location=location.bottom, color=color.new(color.green, 0))
plotchar(dayofweek == dayofweek.saturday,  char='S', location=location.bottom, color=color.new(color.red, 0))
plotchar(dayofweek == dayofweek.sunday,    char='S', location=location.bottom, color=color.new(color.red, 0))
