本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Gideons Gold — ADX Watchman", shorttitle="Gideons Gold — ADX Watchman", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
// ───────────── Settings ─────────────
adxlen = input.int(14, title="ADX Smoothing", minval=1)
dilen = input.int(14, title="DI Length", minval=1)
// ───────────── Directional Movement ─────────────
dirmov(len) =>
up = ta.change(high)
down = -ta.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 = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
// ───────────── ADX Calculation ─────────────
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// ───────────── Histogram ─────────────
histColor = sig <= 20 ? color.red : sig < 22 ? color.yellow : color.green
plot(sig, style=plot.style_columns, color=histColor, title="ADX Histogram", linewidth=2)