RSI Multi Timeframe Based on Moving Average By Alireza Phoenix
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
// © AlirezaPhoenix
// ══════════════════════════════════════════════════════════════════════════════════════════════════ //
//# * ══════════════════════════════════════════════════════════════════════════════════════════════
//# *
//# * Study       : Relative Strength Index Multi Timeframe Based on Moving Average By Alireza Phoenix
//# * Author      : Alireza Phoenix
//# *
//# * Version     : 1.1
indicator(title="Relative Strength Index Multi Timeframe Based on Moving Average By Alireza Phoenix", shorttitle="RSI Multi Timeframe Based on Moving Average By Alireza Phoenix", format=format.price, precision=2 )

len = input(14,  title="Length")
src = input(close, "Source")

up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

offset = input(0 , "RSI Offset")
offset1 = input(0 , "RSI Time1 Offset")
offset2 = input(0 , "RSI Time2 Offset")
plot(rsi, "RSI", color=#7E57C2 , offset = offset)

band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)

fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")

i_res = input.timeframe('120', "Time 1 Resolution" )
s = request.security(syminfo.tickerid , i_res, rsi)
plot(s , 'RSI Time 1', color = color.blue , offset = offset1)

i_res2 = input.timeframe('240', "Time 2 Resolution" )
s2 = request.security(syminfo.tickerid , i_res2, rsi)
plot(s2 , 'RSI Time 2', color=color.red , offset = offset2)

//RSI MA Setup
length1 = input.int(98, 'Fast SMA Length', minval=1)
length2 = input.int(112, 'Slow SMA Length', minval=1)

offset3 = input.int(3, 'Offset Fast SMA', minval=-500, maxval=500)
offset4 = input.int(0, 'Offset Slow SMA', minval=-500, maxval=500)

RSIma1 = ta.wma(2 * ta.wma(s, length1 / 2) - ta.wma(s, length1), math.round(math.sqrt(length1)))
RSIma2 = ta.wma(2 * ta.wma(s2, length2 / 2) - ta.wma(s2, length2), math.round(math.sqrt(length2)))

plot(RSIma1, 'RSI SMA Fast', offset=offset3, color=color.new(#21f3de, 0))
plot(RSIma2, 'RSI SMA Slow', offset=offset4, color=color.new(#ffdf41, 0), display=display.none)