和条件不起作用-新手问题tradingview pinescript

时间:2020-06-12 14:07:05

标签: pine-script

我有以下代码提供随机交叉。我想添加一个AND条件,以便仅在crossBelowstochK都在stochD以上时弹出80。并且只有当crossAbovestochK都在stochD以下时,20才会弹出。
任何帮助,将不胜感激。我确实尝试了各种AND代码,但遇到编译器错误。

//@version=4
study(title="example", overlay=false)

stochK = sma(stoch(close, high, low, 14), 3)
stochD = sma(stochK, 3)

crossBelow = crossunder(stochK, stochD) 
crossAbove = crossover(stochD, stochK) 

plot(series=stochK, color=color.orange)
plot(series=stochD, color=color.teal)

plotshape(series=crossunder(stochK, stochD), style=shape.flag , color=color.red, location=location.abovebar, transp=0)
plotshape(series=crossunder(stochD, stochK), style=shape.flag, color=color.green, location=location.belowbar, transp=0)

1 个答案:

答案 0 :(得分:0)

使用:

crossBelow = crossunder(stochK, stochD) and min(stochK, stochD) > 80
crossAbove = crossover(stochD, stochK) and max(stochK, stochD) < 20

enter image description here