【问题标题】:Crossover and crossunder functions don't respect the parameters I'm giving pine script交叉和交叉功能不尊重我给松树脚本的参数
【发布时间】:2021-02-08 08:01:41
【问题描述】:

我试图在随机时添加一个简单的背景颜色,当 k 高于 80 时,k 在任何时候都超过 d,并且当 k 低于 20 时,k 在任何时候都低于 d。

然而,在这种情况下,我不断收到交叉和交叉信号。在这种情况下,图片中根本没有交叉。

谁能帮我解释一下为什么会这样?

谢谢

//@version=4
study(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, resolution="")
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
cross = input(false, "Highlight Only Crosses in Ob & Os Areas")
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, "K", color=#0094FF)
plot(d, "D", color=#FF6A00)
h0 = hline(80, "Upper Band", color=#606060)
h1 = hline(20, "Lower Band", color=#606060)
fill(h0, h1, color=#9915FF, transp=80, title="Background")

col_ = (k > 80 and crossover(k, d)) or (k < 20 and crossunder(k, d))
         ? na
     : crossunder(k, d)
         ? #d7000080
     : crossover(k, d)
         ? #00d70080
     : na

bgcolor(col_)

【问题讨论】:

    标签: pine-script trading stochastic crossover


    【解决方案1】:
    //@version=4
    study(title="Help (Stochastic RSI)", shorttitle="Stoch RSI", format=format.price, precision=2, resolution="")
    smoothK = input(3, "K", minval=1)
    smoothD = input(3, "D", minval=1)
    lengthRSI = input(14, "RSI Length", minval=1)
    lengthStoch = input(14, "Stochastic Length", minval=1)
    cross = input(false, "Highlight Only Crosses in Ob & Os Areas")
    src = input(close, title="RSI Source")
    rsi1 = rsi(src, lengthRSI)
    k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
    d = sma(k, smoothD)
    plot(k, "K", color=#0094FF)
    plot(d, "D", color=#FF6A00)
    h0 = hline(80, "Upper Band", color=#606060)
    h1 = hline(20, "Lower Band", color=#606060)
    fill(h0, h1, color=#9915FF, transp=80, title="Background")
    
    //col_ = (k > 20 and crossover(d, k)) ? #d7000080 : ((k < 80 and crossunder(d, k)) ? #00d70080 : na)
    col_ = (k > 20 and k[1]<d[1] and k[0]>d[0]) ? #d7000080 : ((k < 80 and k[1]>d[1] and k[0]<d[0]) ? #00d70080 : na)
    
    bgcolor(col_)
    

    【讨论】:

    • 感谢您的回复,但现在它只在超买和向下交叉或超卖和向上交叉时发出信号。我正在寻找的是信号从 20 级下降到 100 级,然后从 0 级上升到 80 级。此外,我仍在努力理解为什么我的代码在没有紫色垂直条的地方发出交叉信号.谢谢
    • 修正了脚本。
    • 谢谢,它现在工作得几乎完美,但仍有时间存在交叉并且它没有突出显示它。例如。我在 60 水平附近有一根蜡烛,它是一个交叉,它发出信号,但下一个蜡烛,总是在同一区域附近,是一个交叉,它没有发出信号。是否可能是交叉/交叉功能无法正常工作?
    • 写下发生这种情况的代码、时间范围和时间。
    • 奇怪,但确实如此。修正了脚本。
    猜你喜欢
    • 2022-01-08
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-11
    • 2019-10-02
    • 1970-01-01
    相关资源
    最近更新 更多