Daily RTH Moving Average On Intraday Timeframes [vnhilton]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vnhilton

//@version=5
indicator("Daily RTH Moving Average On Intraday Timeframes [vnhilton]", "Daily RTH MA", true)

//RTH Timezone
rth = time(timeframe.period, session.regular, syminfo.timezone)

//Get Chart Timeframe
timeframe = timeframe.multiplier

//Minutes Used For Calculating MA Length (up to daily timeframe)
minutes = timeframe.isintraday ? 390 : 1 

//MA Inputs 
len = input.int(5, minval=1, title="MA Daily Length")
src = input(close, title="Source")

//Bollinger Band Inputs
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

//Logic
ma = ta.sma(src, (len * minutes) / timeframe)
dayPrice = ta.stdev(src, (len * minutes) / timeframe)

maRTH = request.security(ticker.modify(syminfo.tickerid, session.regular), timeframe.period, ma)
stdevPriceRTH = mult * request.security(ticker.modify(syminfo.tickerid, session.regular), timeframe.period, dayPrice)

upper = maRTH + stdevPriceRTH
lower = maRTH - stdevPriceRTH

//Plot
averageLine = plot(rth ? maRTH : na, "RTH Daily MA", color.red, style=plot.style_linebr)
upperLine = plot(rth ? upper : na, "Upper Band", color.gray, style=plot.style_linebr)
lowerLine = plot(rth ? lower : na, "Lower Band", color.gray, style=plot.style_linebr)

//Fill
fill(plot1=upperLine, plot2=averageLine, top_value=upper, bottom_value=maRTH, top_color=color.rgb(120, 123, 134, 99), bottom_color=color.rgb(255, 82, 82, 95), title="Upper Band Fill")
fill(plot1=averageLine, plot2=lowerLine, top_value=maRTH, bottom_value=lower, top_color=color.rgb(255, 82, 82, 95), bottom_color=color.rgb(120, 123, 134, 99), title="Lower Band Fill")