I am trying plotting RSI-based moving average line with length= 4000 with and without request.security() function. I want to plot two lines with and without security that overlaps completely.
here's what I did so far. so without security, here is what I wrote for MA1 , which is pretty straight forward
maLengthInput1 = input.int(4000, title="MA Length 1")
rsiMA1 = ma(rsi, maLengthInput1, maTypeInput)
plot(rsiMA1, "MA 1", color=color.blue)
and for the second MA line(MA2) I used security function, I used the length=800 and used 5x timeframe for MA2.
maLengthInput2 = input.int(800, title="MA Length 2")
rsiMA2 = ma(rsi, maLengthInput2, maTypeInput)
// Version 1
maHTF = input.timeframe(title='HTF', defval='5')
rsiMA2_Ver1 = request.security(syminfo.tickerid,maHTF, rsiMA2) // Higher Timeframe 5 Minute
plot(rsiMA2_Ver1, color=color.new(#ff4848, 0), linewidth=1, title='Ma 2 - Version 1', style=plot.style_line)
I also tried the MA2 in another variation like here but it didn't plot at all
// Version 2
current_timeframe = timeframe.multiplier
rsiMA2_Ver2 = request.security(syminfo.tickerid, str.tostring(current_timeframe+4), rsiMA2) // current_timeframe + 4
plot(rsiMA2_Ver2, color=color.new(#ffdd48, 0), linewidth=1, title='Ma 2 - Version 2', style=plot.style_line)
technically speaking all these lines should be overlapping exactly
as 4000 length of 1-Min = 800 length x 5-Min
but the lines are not overlapping.
All I want to plot two lines with and without security that overlaps completely.
when I do the same exercise on Price action, then i get the exact result, however when i try to do that on RSI, I get two different lines instead of one. don't know what am I doing wrong here
Thanks
here is the full code just for reference.
//@version=5
indicator(title="Relative Strength Index", shorttitle="RSI", overlay = false)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI 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))
//rsiPlot = plot(rsi, "RSI", color=color.rgb(158, 158, 158, 63))
//
maLengthInput1 = input.int(4000, title="MA Length 1")
rsiMA1 = ma(rsi, maLengthInput1, maTypeInput)
plot(rsiMA1, "MA 1", color=color.blue)
////
maLengthInput2 = input.int(800, title="MA Length 2")
rsiMA2 = ma(rsi, maLengthInput2, maTypeInput)
// Version 1
maHTF = input.timeframe(title='HTF', defval='5')
rsiMA2_Ver1 = request.security(syminfo.tickerid,maHTF, rsiMA2) // Higher Timeframe 5 Minute
plot(rsiMA2_Ver1, color=color.new(#ff4848, 0), linewidth=1, title='Ma 2 - Version 1', style=plot.style_line)
// Version 2
current_timeframe = timeframe.multiplier
rsiMA2_Ver2 = request.security(syminfo.tickerid, str.tostring(current_timeframe+4), rsiMA2) // current_timeframe + 4
plot(rsiMA2_Ver2, color=color.new(#ffdd48, 0), linewidth=1, title='Ma 2 - Version 2', style=plot.style_line)
hline(50)
///