Highlight candles by time by Vincent
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © u_20bf

//@version=5
indicator('Highlight candles by time', overlay=true)

// Inputs
// TODO: Provide better options
display_timeframes = input.string(title='What timeframes to display ?', defval='M5', options=['M5', 'M15', 'M30','H1' ,'H4'])

// Times need to be the exchange timezone right now (eg +2 from GMT for FXCM)
display_period_one = input.bool(true, 'Display period one?')
period_one_session = input.session('1600-1900', 'Period one times')

display_period_two = input.bool(false, 'Display period two?')
period_two_session = input.session('0800-0900', 'Period two times')

display_period_three = input.bool(false, 'Display period three?')
period_three_session = input.session('1200-1300', 'Period three times')

// TODO: Colour per session
candle_colour = color.yellow

// Checks
display_on_current_timeframe = display_timeframes == 'M5' 

is_in_session = (display_period_one and time(timeframe.period, period_one_session)) or (display_period_two and time(timeframe.period, period_two_session)) or (display_period_three and time(timeframe.period, period_three_session))
can_colour_candle = display_on_current_timeframe and is_in_session

// Colouring
barcolor(color=can_colour_candle ? candle_colour : na)