尝试在 Pine 脚本中制作适用于不同时间尺度的 RSI 指标

Tring to make an RSI indicator that works on different time scales in Pine script

好的,我的代码是这样的:

rsilength = input(14, title="RSI Length", type=input.integer)
//200 SMA
sma = sma(close, input(200))
rsiset = rsi(close, rsilength)
rsiW = security(syminfo.tickerid, "W", rsiset)  // 1 Week
rsiD = security(syminfo.tickerid, "D", rsiset)  // 1 Day
rsi4h = security(syminfo.tickerid, "240", rsiset) // 4h

if rsi4h == rsiset
    sma := sma(close, input(1200))
if rsiD == rsiset
    sma := sma(close, input(200))
if rsiW == rsiset
    sma := sma(close, input(29))

我正在尝试让 sma 图正确显示在日线图、4 小时线图和周线图上。

它正在工作。 SMA 线在所有 3 个时间范围内绘制得很好。但是我收到警告

The function 'sma' should be called on each calculation for consistency. It is recommended to extract the call from this scope.

有没有办法写同样的东西而不得到警告? RSI 也工作得很好(我在代码的后面使用它们。唯一困扰我的是 ifs

中每个 sma 的 3 个警告
//@version=4
study("My Script")

var int     myInput = 1

rsilength   = input(14, title="RSI Length", type=input.integer)

sma         = sma(close, input(200))

rsiset      = rsi(close, rsilength)
rsiW        = security(syminfo.tickerid, "W",   rsiset) // 1 Week
rsiD        = security(syminfo.tickerid, "D",   rsiset) // 1 Day
rsi4h       = security(syminfo.tickerid, "240", rsiset) // 4h

if rsi4h == rsiset
    myInput := input(1200, "input rsi4h")
else if rsiD == rsiset
    myInput := input( 200, "input rsiD")
else if rsiW == rsiset
    myInput := input(  29, "input rsiW")

sma := sma(close, myInput)

plot(sma)