Double Relative Strength Index (Double RSI)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Arun_K_Bhaskar

//@version=5

indicator(title="Double Relative Strength Index (Double RSI)", shorttitle="Double RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

i_show_rsi_1 = input.bool(defval=true, title='', inline='R1')
i_length_1 = input.int(defval=5, title='Length', minval=1, inline='R1')

i_show_rsi_2 = input.bool(defval=true, title='', inline='R2')
i_length_2 = input.int(defval=10, title='Length', minval=1, inline='R2')

i_source = input.source(defval=close, title='Source', inline='')
i_smoothing = input.string(defval='RMA', title='Smoothing', options=['None', 'RMA', 'SMA', 'EMA', 'WMA', 'HMA'], inline='')
i_show_candle = input.bool(defval=true, title='Crossing Candles', tooltip='', inline='')

moving_average(source, length) =>
	switch i_smoothing
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		"WMA" => ta.wma(source, length)
        "HMA" => ta.hma(source, length)

rsi_1 = i_smoothing == "None" ? ta.rsi(i_source, i_length_1) : moving_average(ta.rsi(i_source, i_length_1), i_length_1)
rsi_2 = i_smoothing == "None" ? ta.rsi(i_source, i_length_2) : moving_average(ta.rsi(i_source, i_length_2), i_length_1)

color_1 = #00ff00
color_2 = #ff0000
rsi_col = rsi_1 > rsi_2 ? color_1 : color_2
crossover_color = i_show_candle and ta.crossover(rsi_1, rsi_2) ? #00FFFF : na
crossunder_color = i_show_candle and ta.crossunder(rsi_1, rsi_2) ? #FF00FF : na

plot(i_show_rsi_1 ? rsi_1 : na, title = "RSI Fast", color=rsi_col)
plot(i_show_rsi_2 ? rsi_2 : na, title = "RSI Slow", color=rsi_col)

barcolor(color=crossover_color, title='Crossover Candle')
barcolor(color=crossunder_color, title='Crossunder Candle')

// RSI Bands
band90 = hline(80, "RSI 90%", linestyle=hline.style_dotted, color=color.new(color_2, 75))
band80 = hline(75, "RSI 80%", linestyle=hline.style_dotted, color=color.new(color_2, 75))
band60 = hline(55, "RSI 60%", linestyle=hline.style_dotted, color=color.new(color.silver, 75), linewidth=1)
band50 = hline(50, "RSI 50%", linestyle=hline.style_dotted, color=color.new(color.silver, 75), linewidth=1)
band40 = hline(45, "RSI 40%", linestyle=hline.style_dotted, color=color.new(color.silver, 75), linewidth=1)
band20 = hline(25, "RSI 20%", linestyle=hline.style_dotted, color=color.new(color_1, 75))
band10 = hline(20, "RSI 10%", linestyle=hline.style_dotted, color=color.new(color_1, 75))

fill(band80, band90, color=color.new(color_2, 95), title="RSI Upper")
fill(band40, band60, color=color.new(color.silver, 95), title="RSI Middle")
fill(band10, band20, color=color.new(color_1, 95), title="RSI Lower")