Pine脚本,确定随机交叉的闭合程度低于上次随机交叉的闭合程度

时间:2020-09-02 07:53:15

标签: pine-script

我是Pine脚本的初学者。我只能确定随机交叉。我只是想学习如何在随机交叉的前一个收盘价之下确定随机交叉的收盘价。非常感谢您的回复! example image

//@version=4
study(title="Stochastic", shorttitle="Stoch", overlay=true)
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

overbought = 80
oversold = 20

co = crossover(k,d) and k[1] < oversold
cu = crossunder(k,d) and k[1] > overbought

plotshape(co, location = location.belowbar)
plotshape(cu, location = location.abovebar)

1 个答案:

答案 0 :(得分:0)

valuewhen()是您的朋友:

//@version=4
study(title="Stochastic", shorttitle="Stoch", overlay=true)
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

overbought = 80
oversold = 20

co = crossover(k,d) and k[1] < oversold
cu = crossunder(k,d) and k[1] > overbought
coLower = close < valuewhen(co, close, 1)

plotshape(co, location = location.belowbar)
plotshape(cu, location = location.abovebar)
bgcolor(co and coLower ? color.lime : na)

enter image description here