高于 80 和低于 20 的随机 %D 值

Stochastic %D values above 80 and below 20

这是我编写的一个简单脚本,用于指示简单的反转模式。我想添加到每一行,因此当随机 %D 高于 80 时将触发红色向下箭头,当 %D 低于 20 时触发绿色向上箭头。

study("Ringed HL", overlay=true)
datadown = open[1] > open[2] and close[1] > close[2] and close[2] > open[2] and close[1] > open[1] and close < open
dataup =  open[1] < open[2] and close[1] < close[2] and close[2] < open[2] and close[1] < open[1] and close > open
plotshape(datadown, style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(dataup, style=shape.triangleup, location=location.belowbar, color=color.green)

我不确定我是否理解你的问题。

你叫随机指标了吗?

X= stoch(source, high, low, length)

我想这就是您要找的。
我添加了一个复选框输入以显示所有箭头 below/above 阈值。
如果未选中,它只会在穿过阈值时显示第一个箭头。

//@version=4
study("Ringed HL", overlay=true)

Length          = input (14, minval=1, title = "Stochastic Length")
k               = input ( 1, minval=1, title = "Stochastic %K")
d               = input ( 5, minval=1, title = "Stochastic %D")
showAll         = input(false)

sto             = stoch (close, highest(Length), lowest(Length), Length)
K               = sma (sto, k)
D               = sma (sto, d)


D_over_80       = D > 80
D_under_20      = D < 20

show_D_over_80  = showAll ? D_over_80  : D_over_80  != D_over_80[1]  ? D_over_80  : na 
show_D_under_20 = showAll ? D_under_20 : D_under_20 != D_under_20[1] ? D_under_20 : na 

plotshape(show_D_over_80,  style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(show_D_under_20, style=shape.triangleup,   location=location.belowbar, color=color.green)

更新:代码与原问题代码整合。

//@version=4
study("Ringed HL", overlay=true)

Length          = input (14, minval=1, title = "Stochastic Length")
k               = input ( 1, minval=1, title = "Stochastic %K")
d               = input ( 5, minval=1, title = "Stochastic %D")
showAll         = input(false)

sto             = stoch (close, highest(Length), lowest(Length), Length)
K               = sma (sto, k)
D               = sma (sto, d)

D_over_80       = D > 80
D_under_20      = D < 20

datadown        = open[1] > open[2] and close[1] > close[2] and close[2] > open[2] and close[1] > open[1] and close < open
dataup          = open[1] < open[2] and close[1] < close[2] and close[2] < open[2] and close[1] < open[1] and close > open

show_datadown   = datadown and D_over_80
show_dataup     = dataup   and D_under_20

plotshape(show_datadown, style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(show_dataup, style=shape.triangleup, location=location.belowbar, color=color.green)