0

我正在交易视图上尝试使用 pine 脚本。我希望每当 DI+ 与 DI- 交叉时,它应该将测试警报显示为绿色的“CSO”,同样,当 DI- 与 DI+ 交叉的“CSO”为红色时。

但是在这个脚本中,当我使用 plotshape 时,我松开了 DI+ 和 DI- 线。

请指导。 在此处输入图像描述

study("Indi_ADX")
len = input(title="Length", type=integer, defval=14)
th = input(title="threshold", type=integer, defval=25)
//avg = input(title="SMA", type=integer, defval=10)

TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0


SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - 
(nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - 
(nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
//ADX = sma(DX, len)
//SMA = sma(ADX, avg)

CSOG = crossover(DIPlus, DIMinus)
CSOR = crossover(DIMinus,DIPlus)

plot(DIPlus, color=green, title="DI+")
plot(DIMinus, color=red, title="DI-")
//plot(ADX, color=yellow, title="ADX")
//plot(SMA, color=white, title="SMA")
hline(th, color=black, linestyle=dashed)
plotshape(series=CSOG, title="CSO", location=location.abovebar, color=green, text="CSO", 
size=size.small)
plotshape(series=CSOR, title="CSO", location=location.abovebar, color=red, text="CSO", 
size=size.small)
4

0 回答 0