//@version=5
indicator("Multi-timeframe RSI-based MA", overlay=false)
// Inputs for RSI period and length for moving averages
rsiPeriod = input.int(14, title="RSI Period")
maLength1 = input.int(10, title="MA Length for 1-minute RSI-based MA")
maLength5 = input.int(10, title="MA Length for 5-minute RSI-based MA")
// Calculate RSI for current timeframe
rsi = ta.rsi(close, rsiPeriod)
// Calculate moving averages based on RSI for 1-minute and 5-minute timeframes
rsi_ma_1m = ta.sma(request.security(syminfo.tickerid, "1", rsi), maLength1)
rsi_ma_5m = ta.sma(request.security(syminfo.tickerid, "5", rsi), maLength5)
// Plot the RSI-based moving averages
plot(rsi_ma_1m, color=color.blue, title="RSI-based MA (1m)", linewidth=2)
plot(rsi_ma_5m, color=color.red, title="RSI-based MA (5m)", linewidth=2)
// Add RSI line for reference (optional)
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
plot(rsi, title="RSI", color=color.purple, linewidth=1)