Extended Session High/Low - Intraday and daily charts
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © valpatrad

//@version=5
indicator('Extended Session High/Low', '', true, precision=2)


if timeframe.isseconds or timeframe.isweekly or timeframe.ismonthly
    runtime.error('The indicator does not work on seconds, weekly or monthly time frames.')


	//Menu
ES_time_in = input.session('1600-0930', 'Extended Session')
ES_last = input.bool(true, 'Last only')

	//Intraday Variables
ES_time = time(timeframe.period, ES_time_in)
var float ES_high = na
var float ES_low = na
if na(ES_time)[1] and not na(ES_time)
    ES_high := high
    ES_low := low
if not na(ES_time)
    ES_high := high > ES_high ? high : ES_high
    ES_low := low < ES_low ? low : ES_low

	//Daily Variables
ticker = ticker.new(syminfo.prefix, syminfo.ticker, session.extended)
ES_highs = request.security_lower_tf(ticker, '1', not session.ismarket ? high : na)
ES_lows = request.security_lower_tf(ticker, '1', not session.ismarket ? low : na)
DES_high = array.max(ES_highs)
DES_low = array.min(ES_lows)

    //Plot Variables
float ES_max = 0.
float ES_min = 0.
if timeframe.isintraday
	ES_max := ES_high
	ES_min := ES_low
else
	ES_max := DES_high
	ES_min := DES_low

	//Plot
plot(ES_max, 'Extended Session High', color.new(#00FF00, 35), 2, plot.style_circles, true, offset=ES_last ? -9999 : 0)
plot(ES_min, 'Extended Session Low', color.new(#FF0000, 35), 2, plot.style_circles, true, offset=ES_last ? -9999 : 0)