本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//Created by @TraderR0BERT, NETWORTHIE.COM, last updated 01/26/2016
// Edit by @GeertVD
//DMI Indicator
//Resolution input option for higher/lower time frames
study(title="DMI ADX TREND 2.0", shorttitle="ADX TREND 2.0")
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
ADX_wm_threshold=input(20,title="ADX weak to medium threshold")
ADX_ms_threshold=input(40,title="ADX medium to strong threshold")
osob=input(60,title="ADX exhaustion level")
HighlightMC=input(true, title="Highlight momentum change?", type=bool)
thold = input(20, title="ADX Threshold")
DIpDImCE = input(false, title="Show DI+ vs DI- contraction/expansion histogram?", type=bool)
ADX_wm_threshold_f= ADX_wm_threshold < ADX_ms_threshold ? ADX_wm_threshold : 20
ADX_ms_threshold_f= ADX_wm_threshold < ADX_ms_threshold ? ADX_ms_threshold : ADX_wm_threshold+20
osob_f=ADX_ms_threshold < osob ? osob : ADX_ms_threshold+20
threshold = thold
//Script for Indicator
dirmov(len) =>
up = change(high)
down = -change(low)
truerange = rma(tr, len)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, 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)
[adx, plus, minus]
[sig, up, down] = adx(dilen, adxlen)
col = sig >= sig[1] ? green : sig <= sig[1] ? red : gray
//Plot Definitions Current Timeframe
p1 = plot(sig, color=blue, linewidth = 1, title="ADX", transp=10)
//p2 = plot(sig, color=col, style=circles, linewidth=3, title="ADX")
p3 = plot(up, color=green, linewidth = 2, title="+DI", transp=10)
//p4 = plot(up, color=blue, style=circles, linewidth=3, title="+DI")
p5 = plot(down, color=red, linewidth = 2, title="-DI", transp=10)
//p6 = plot(down, color=fuchsia, style=circles, linewidth=3, title="-DI")
h0=hline(0, linestyle=dotted, color=black, linewidth = 1, title="ADX = 0 Line")
h_wm=hline(ADX_wm_threshold_f, linestyle=dotted, color=black, linewidth = 1, title="ADX weak to medium threshold")
h_ms=hline(ADX_ms_threshold_f, linestyle=dotted, color=black, linewidth = 1, title="ADX medium to strong threshold")
h_osob=hline(osob_f, linestyle=dotted, color=black, linewidth = 1, title="ADX exhaustion threshold")
fill(h0, h_wm, title="ADX = weak", color=red, transp=90)
fill(h_wm, h_ms, title="ADX = medium", color=yellow, transp=90)
fill(h_ms, h_osob, title="ADX = strong", color=green, transp=90)
//fill(h75, h100, title="ADX = 75 to 100", color=green, transp=70)
//trender = (sig >= up or sig >= down) ? 1 : 0
//bgcolor(trender>0 ? green : red, transp=85)
b_color = cross(up,down) and up>down and sig > threshold ? green : cross(up,down) and up<down and sig > threshold ? red : na
bgcolor(HighlightMC ? b_color : na, title="Momentum change (strong)", transp=70)
outHist=up-down
histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0
plot_color = histA_IsUp ? lime : histA_IsDown ? #006400 : histB_IsDown ? red : histB_IsUp ? #8B0000 : na
plot(DIpDImCE ? outHist : na, title="DI+ vs DI- Contraction/Expansion", color=plot_color, style=histogram, linewidth=2, transp=10)
//Alert Function for ADX crossing Threshold
Up_Cross = crossover(up, threshold)
alertcondition(Up_Cross, title="DMI+ cross", message="DMI+ Crossing Threshold")
Down_Cross = crossover(down, threshold)
alertcondition(Down_Cross, title="DMI- cross", message="DMI- Crossing Threshold")