Multi Type RSI [Misu]
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
//@version=5
indicator(title="Multi Type RSI [Misu]", shorttitle="Multi RSI [Misu]", format=format.price, precision=2)

ma(source, length, type) =>
    switch type
        "SMMA (RMA)" => ta.rma(source, length)
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiSourceInput  = input.source(close, "Source", group="RSI Settings")
lenRsi          = input.int(14, minval=1, title="Lenght RSI", group="RSI Settings")
rsiMaTypeInput  = input.string("EMA", title="RSI MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI Settings")

lenFastMA       = input.int(3, minval=1, title="Fast Lenght MA", group="RSI Settings")
lenSlowMA       = input.int(5, minval=1, title="Slow Lenght MA", group="RSI Settings")
maTypeInput     = input.string("EMA", title="Smoothing MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI Settings")

lenLowerBand    = input.float(25, minval=1, title="Lower Band", group="RSI Settings")
lenUpperBand    = input.float(75, minval=1, title="Upper Band", group="RSI Settings")

signalType      = input.string("Cross 2 Mas", options=["Cross 2 Mas", "Cross Ma/Bands"], title="Signal Type", group="RSI Settings")

up     = ma(math.max(ta.change(rsiSourceInput), 0), lenRsi, rsiMaTypeInput)
down   = ma(-math.min(ta.change(rsiSourceInput), 0), lenRsi, rsiMaTypeInput)
rsi     = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// ---

rsiMaF      = ma(rsi,lenFastMA, maTypeInput)
rsiMaS      = ma(rsi,lenSlowMA, maTypeInput)
// ---

// Plot Rsi.
plot_0 = plot(rsiMaF, "RSI Slow", color=color.green, linewidth=1)
plot_1 = plot(rsiMaS, "RSI Fast", color=color.red, linewidth=1)


// Draw Bands.
rsiUpperBand = hline(lenUpperBand, "RSI Dmi Upper Band", color=#787B86)
hline(50, "RSI Dmi Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(lenLowerBand, "RSI Dmi Lower Band", color=#787B86)

// Define Cross params & Draw circles.
crossSell = signalType == "Cross 2 Mas" ? ta.crossunder(rsiMaF, rsiMaS) and rsiMaF > lenUpperBand : ta.crossunder(rsiMaF, lenUpperBand)
crossBuy = signalType == "Cross 2 Mas" ? ta.crossover(rsiMaF, rsiMaS) and rsiMaF < lenLowerBand : ta.crossover(rsiMaF, lenLowerBand)
alertcondition(crossSell, "Sell Signal", "Sell Signal")
alertcondition(crossBuy, "Buy Signal", "Buy Signal")

plot(crossSell ? rsiMaF: na, 'RSI Red Dots'
  , color = color.red
  , style = plot.style_circles
  , linewidth = 4)
  
plot(crossBuy ? rsiMaF: na, 'RSI Green Dots'
  , color = color.green
  , style = plot.style_circles
  , linewidth = 4)
  
// Fill Over.
rsiClamp = plot(math.max(lenLowerBand, math.min(lenUpperBand, rsiMaF)), title = "RSI Clamped (Not Used)", color = #00000000, editable = false)
fill(plot_0, rsiClamp, title = "Over Fill", color = rsi < 50 ? color.new(color.green, 50) : color.new(color.red, 50))

// Fill.
colorFill = rsiMaF > lenUpperBand ? color.new(color.red, 100) : rsiMaF < lenLowerBand ? color.new(color.green, 100) : rsiMaF < rsiMaS ? color.new(color.red, 90) : color.new(color.green, 90)
fill(plot_1, plot_0, colorFill)

