Short Sale Restriction (SSR) Level - 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('Short Sale Restriction Level', 'SSR', 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
SSR_last = input.bool(true, 'Last only', group='Short Sale Restriction Level')

	//Variables
ES_time = time(timeframe.period, '1600-0930')
ES_start = timestamp(syminfo.timezone, year(timenow), month(timenow), dayofmonth(timenow), 16, 0)
ES_end = timestamp(syminfo.timezone, year(timenow), month(timenow), dayofmonth(timenow), 9, 30)
ticker = ticker.new(syminfo.prefix, syminfo.ticker, session.extended)
ES_closes = request.security_lower_tf(ticker, '1', not na(ES_time) ? close : na)
ES_close = array.max(ES_closes)
SSR_ytd = request.security(syminfo.tickerid, 'D', close[1])
SSR_tdy = request.security(syminfo.tickerid, 'D', close)
var float SSR = 0.
if timeframe.isintraday and not na(ES_time) or timeframe.isdaily and timenow >= ES_start and ES_close > 0 or timeframe.isdaily and timenow < ES_end and ES_close > 0
    SSR := SSR_tdy * 0.9
else
    SSR := SSR_ytd * 0.9

	//Plot
plot(SSR, 'Short Sale Restriction Level', color.new(#FFFFFF, 50), 1, plot.style_line, true, offset=SSR_last ? -9999 : 0)