本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//ADX and DI Indicator by Max Saham
//@version=1
study("MAX SAHAM ADX with DI ", shorttitle="MAX SAHAM ADX with DI ")
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
th = input(title="threshold", type=integer, defval=20)
sbh = true
sch = true
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
[plus, minus] = dirmov(dilen)
sig = adx(dilen, adxlen)
plot(plus, color = green, linewidth=2, title="plusDI")
plot(minus, color = red, linewidth=2, title="minusDI")
plot(sig, color=white, linewidth=2, title="ADX")
hline(th, color=yellow, linestyle=dashed)
aboveLine = sig > th ? 1 : 0
belowLine = sig < th ? 1 : 0
bgcolor(sbh and aboveLine ? #00FF00 : na, title="Trend Area", transp=95)
bgcolor(sbh and belowLine ? #FF5252 : na, title="No Trend", transp=95)
plot(crossover(plus, minus) ? plus : na, title="Positive Trend", style=circles, linewidth=6, color=lime)
plot(crossunder(plus, minus) ? plus : na, title="Negative Trend", style=circles, linewidth=6, color=red)
plot(crossover(plus, sig) ? plus : na, title="Trend Spike", style=circles, linewidth=8, color=#87CEFA)