Smoothed RSI w/ VWAP & Moving Average
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DDMyke

//@version=5
indicator(title="Smoothed RSI w/ VWAP & Moving Average", shorttitle="RSIv", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

rsiSourceInput = input.source(close, "Source", group="RSI Settings")
showRSI = input.bool(true, 'RSI', inline='rv', group="RSI Settings")
showRSIvwap = input.bool(true, 'VWAP', inline='rv', group="RSI Settings")
showbarcolor = input.bool(false, 'Barcolor', inline='rv', group="RSI Settings")

rsiLengthInput = input.int(14, minval=1, title="Length", group="RSI Settings")
rsiSmoothing = input.int(2,'smoothing', group="RSI Settings")
rsiWidth = input.int(1, 'Width', group="RSI Settings")

showMA = input.bool(true, 'Moving Average', group="MA Settings")
maTypeInput = input.string("WMA", title="Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA", "VWAP"], group="MA Settings")
maLengthInput = input.int(34, title="Length", group="MA Settings")
maWidth = input.int(1, 'Width', group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, step=0.25, title="BB StdDev", group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
smoorsi = ta.rma(rsi,rsiSmoothing)

ma(smoorsi, maLengthInput, maTypeInput) =>
    switch maTypeInput
        "SMA" => ta.sma(smoorsi, maLengthInput)
        "Bollinger Bands" => ta.sma(smoorsi, maLengthInput)
        "EMA" => ta.ema(smoorsi, maLengthInput)
        "SMMA (RMA)" => ta.rma(smoorsi, maLengthInput)
        "WMA" => ta.wma(smoorsi, maLengthInput)
        "VWMA" => ta.vwma(smoorsi, maLengthInput)
        "VWAP" => ta.vwap(smoorsi)

rsiMA = ma(smoorsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

//-------------------------------------------------------------- VWAP
RSIvwap = ta.vwap(smoorsi)

//-------------------------------------------------------------- Plots
StrongBull = smoorsi > 55 and smoorsi > rsiMA and smoorsi > RSIvwap
Bullish = smoorsi > 55 and smoorsi < rsiMA and smoorsi > RSIvwap
StrongBear = smoorsi < 45 and smoorsi < rsiMA and smoorsi < RSIvwap
Bearish = smoorsi > 45 and smoorsi < rsiMA and smoorsi < RSIvwap 
Neutral = smoorsi > 45 or smoorsi < 55 
colorchange = StrongBull ? color.new(#00ff00,0) : Bullish ? color.new(#1b5e20,0) : Bearish ? color.new(#801922,0) : StrongBear ? color.new(#ff0000,0) : Neutral ? color.new(#ffffff,0) : na

plot(showRSI ? smoorsi : na, "Smoothed RSI", color=colorchange, linewidth=rsiWidth)
plot(showRSIvwap ? RSIvwap : na, "RSI-based VWAP", color=color.new(#5b9cf6,50), linewidth=rsiWidth)

bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.new(#b2b5be,65), style=plot.style_line)
plot(showMA ? rsiMA : na, "RSI-based MA", color=color.new(#b2b5be,65), linewidth=maWidth, style=plot.style_line)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.new(#b2b5be,65), style=plot.style_line)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(#0000ff,95) : na, title="Bollinger Bands Background")

barcolor = StrongBull ? color.new(#00ff00,20) : Bullish ? color.new(#1b5e20,20) : Bearish ? color.new(#801922,20) : StrongBear ? color.new(#ff0000,20) : color.new(#ffffff,20)
barcolor(showbarcolor ? barcolor : na)

//-------------------------------------------------------------- Hlines
rsiUpperBand = hline(75, "RSI Upper Band", color=color.new(#131722,0), linestyle=hline.style_dotted)
midBand = hline(50, "RSI Middle Band", color=color.new(#2a2e39,0), linestyle=hline.style_dotted)
rsiLowerBand = hline(25, "RSI Lower Band", color=color.new(#131722,0), linestyle=hline.style_dotted)
fill(rsiUpperBand, midBand, color=color.new(#00ff00,98), title="Upper Fill")
fill(midBand, rsiLowerBand, color=color.new(#ff0000,98), title="Lower Fill")


