我想在随机时添加一个简单的背景颜色,k 在任何时间越过 d 但当 k 大于 80 时,同样 k 在任何时间越过 d 但当 k 低于 20 时。
然而,在这种情况下,我不断收到交叉和交叉信号。在图片中的这种情况下,根本没有交叉。
谁能帮我解释为什么会发生这种情况?
谢谢
//@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_)
//@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 级左右的蜡烛,这是一个交叉,它发出信号,但下一根蜡烛,总是在同一区域附近,是一个交叉,它没有发出信号。交叉/交叉功能是否可能无法正常工作?
写下这种情况发生的代码、时间范围和时间。
很奇怪,但确实如此。修复了脚本。