首页 > 解决方案 > 绘图功能未在 pine 脚本中显示所需的结果

问题描述

我是 pine 脚本的新手。我试图在 pine 脚本中创建 Bar RSI 和 Stochastic,但绘图函数未显示预期结果。

当我取消选中显示 RSI 选项时,RSI 仍然绘制在图表上。谁能帮我解决这个问题

// Inputs
src = input(close, title = "RSI Source")
len = input(defval=9, title = "RSI Length", minval = 2, maxval = 100, type=input.integer)
std_bar = input("Std", title = "RSI Style", options = ["Bar", "Std"])
inner = input("Dynamic", title = "RSI Levels Type", options = ["Dynamic", "Fixed", "NA"])
inner_type = input("Standard Deviation", title = "Calculation Method", options = ["Standard Deviation", "Smooth Moving Average"])

inner_mult = input(1.0, title = "Multiplier", minval = 0.0, maxval = 4.0, step = 0.1)
lengthStoch = input(14, "Stochastic Length", minval=1)
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)

//Show
rl = input(true,title="Show RSI", group="Display Settings")
sl = input(false,title="Show Stoch RSI", group="Display Settings")

//Calculation
norm = if std_bar=="Std"
    1
else
    avg(src, src[1])
    
RSI = rsi(src, len)

RSI_ch = if inner != "NA"
    if inner_type == "Standard Deviation"
        stdev(abs(change(RSI)), len)
    else
        rma(abs(change(RSI)), len)

//RSI Bars
o = std_bar=="Bar" ? RSI[1] : RSI
h = std_bar=="Bar" ? RSI : RSI
l = std_bar=="Bar" ? RSI[1] : RSI
c = std_bar=="Bar" ? RSI : RSI

//Stochastic
k = sma(stoch(RSI, RSI, RSI, lengthStoch), smoothK)
d = sma(k, smoothD)

//Plot

plotbar(o,h,l,c, title="Bar RSI")
plot(rl and std_bar=="Bar" ? na : RSI, color = color.orange, title = "RSI", linewidth = 2)
plot(sl and k ? k : na, "K", color=#0094FF)
plot(sl and d ? d : na, "D", color=#FF6A00)```

标签: pine-script

解决方案


您的三元陈述似乎与您想要的相反。尝试:

plot(rl and std_bar=="Bar" ? RSI : na, color = color.orange, title = "RSI", linewidth = 2)

推荐阅读