本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ═══════════════════════════════════════════════════════════════════════════
// ADX ULTIMATE | Trend Strength Made Simple (v1.2)
// Built for Forex, works on any market and any timeframe.
//
// QUICK GUIDE (read this once, then forget the indicator needs a manual):
// • THICK LINE = ADX → HOW STRONG the trend is (NOT which way it goes)
// • GREEN LINE = +DI → buyers' pressure
// • RED LINE = -DI → sellers' pressure
// • Line color/zone tells you the strength level:
// grey (<20) = ranging, no real trend
// yellow (20-25)= a trend may be waking up
// blue (25-40)= healthy trend
// orange (40-50)= very strong trend
// purple (50+) = extreme, trend may be exhausted
// • Markers: UP / DOWN triangles = buyers / sellers just took control
// white circle = a trend is starting (ADX crossed "trending")
// white diamond = a very strong trend just peaked (tiring)
// • Dashboard: strength meter, setup quality stars, a suggested stance
// ("what to do now") and the next thing to watch for.
//
// Educational guide based on ADX/DMI only. Not financial advice.
// Always combine with price action, levels and your own risk management.
// ═══════════════════════════════════════════════════════════════════════════
indicator("ADX Ultimate | Trend Strength Made Simple", shorttitle="ADX Ultimate", precision=1)
// ───────────────────────────── INPUTS ─────────────────────────────
G1 = "1) Core settings"
preset = input.string("Standard (14)", "Style preset", options = ["Scalper (10)", "Standard (14)", "Swing (20)", "Custom"], group = G1,
tooltip = "Scalper = faster, noisier (M1-M15).\nStandard = the classic Wilder setting, fine for everything.\nSwing = slower, smoother (H4-D1).")
customLen = input.int(14, "Custom: DI length", minval = 2, group = G1)
customSmooth = input.int(14, "Custom: ADX smoothing", minval = 2, group = G1)
G2 = "2) Strength levels"
weakLvl = input.int(20, "Ranging below", minval = 5, maxval = 40, group = G2, tooltip = "Below this, the market is considered directionless.")
trendLvl = input.int(25, "Trending above", minval = 10, maxval = 50, group = G2, tooltip = "Classic confirmation level for a real trend.")
strongLvl = input.int(40, "Very strong above", minval = 20, maxval = 60, group = G2)
extremeLvl = input.int(50, "Extreme above", minval = 30, maxval = 70, group = G2, tooltip = "Trends this strong are often mature. Chasing here is risky.")
G3 = "3) Signals"
showSignals = input.bool(true, "Show signal markers", group = G3)
sigMin = input.int(20, "Min ADX for direction signals", minval = 5, maxval = 50, group = G3,
tooltip = "A +DI/-DI cross only counts when ADX is at least this high. Filters out most ranging-market noise.")
requireRising = input.bool(false, "Only signal when ADX is rising", group = G3)
G4 = "4) Look & feel"
showZones = input.bool(true, "Colored strength zones", group = G4)
showDI = input.bool(true, "Show +DI / -DI lines", group = G4)
showGlow = input.bool(true, "ADX glow effect", group = G4)
highlightRange = input.bool(true, "Tint background when ranging", group = G4)
G5 = "5) Dashboard & higher timeframe"
dashMode = input.string("Compact", "Dashboard", options = ["Full", "Compact", "Off"], group = G5,
tooltip = "Compact = 5 short rows with the suggested stance. Full = every detail. Off = hide it completely.\n\nThe stance is an educational reading of ADX/DMI only, not financial advice.")
dashPosStr = input.string("Top left", "Position", options = ["Top left", "Top right", "Bottom left", "Bottom right"], group = G5,
tooltip = "Top left keeps the newest candles (right side) clear.")
dashSizeStr = input.string("Small", "Text size", options = ["Small", "Normal", "Large"], group = G5)
htfChoice = input.string("Auto", "Higher timeframe check", options = ["Auto", "15", "60", "240", "D", "W", "M"], group = G5,
tooltip = "Auto picks a sensible higher timeframe for the chart you are on (e.g. M15 → H4, H1 → D1). Trading with the higher-timeframe trend improves odds.")
// ───────────────────────────── CALCULATION ─────────────────────────────
diLen = switch preset
"Scalper (10)" => 10
"Swing (20)" => 20
"Custom" => customLen
=> 14
adxSmooth = switch preset
"Scalper (10)" => 10
"Swing (20)" => 20
"Custom" => customSmooth
=> 14
f_dmi() =>
[p, m, a] = ta.dmi(diLen, adxSmooth)
[p, m, a]
[plusDI, minusDI, adx] = f_dmi()
// Strength state: 0 ranging, 1 waking up, 2 trending, 3 strong, 4 extreme
state = adx >= extremeLvl ? 4 : adx >= strongLvl ? 3 : adx >= trendLvl ? 2 : adx >= weakLvl ? 1 : 0
// Momentum of the trend itself
slope = adx - nz(adx[3])
rising = slope > 0.6
falling = slope < -0.6
bull = plusDI > minusDI
// ───────────────────────────── HIGHER TIMEFRAME ─────────────────────────────
secs = timeframe.in_seconds()
autoTf = secs <= 60 ? "15" : secs <= 300 ? "60" : secs <= 900 ? "240" : secs <= 3600 ? "D" : secs <= 14400 ? "W" : "M"
htfTf = htfChoice == "Auto" ? autoTf : htfChoice
htfOk = timeframe.in_seconds(htfTf) > secs
[hP, hM, hA] = request.security(syminfo.tickerid, htfTf, f_dmi(), lookahead = barmerge.lookahead_off)
htfTrending = htfOk and not na(hA) and hA >= trendLvl
htfBias = htfTrending ? (hP > hM ? 1 : -1) : 0
f_tfLabel(string tf) =>
s = timeframe.in_seconds(tf)
s >= 2419200 ? "1M" : s >= 604800 ? "1W" : s >= 86400 ? "1D" : s >= 3600 ? str.tostring(s / 3600, "#") + "H" : str.tostring(s / 60, "#") + "m"
// ───────────────────────────── COLORS ─────────────────────────────
cGrey = #787B86
cYellow = #FFEB3B
cBlue = #4FC3F7
cOrange = #FF9800
cPurple = #E040FB
cGreen = #00C853
cRed = #FF3D57
cDark = #0F1320
cText = #D1D4DC
stateCol = switch state
0 => cGrey
1 => cYellow
2 => cBlue
3 => cOrange
=> cPurple
// ───────────────────────────── ZONES ─────────────────────────────
topLvl = extremeLvl + 10
h0 = hline(0, "Zero", display = display.none)
hW = hline(weakLvl, "Ranging", color = color.new(cGrey, 40), linestyle = hline.style_dotted)
hT = hline(trendLvl, "Trending", color = color.new(cBlue, 40), linestyle = hline.style_dotted)
hS = hline(strongLvl, "Very strong", color = color.new(cOrange, 40), linestyle = hline.style_dotted)
hE = hline(extremeLvl, "Extreme", color = color.new(cPurple, 40), linestyle = hline.style_dotted)
hTop = hline(topLvl, "Top", display = display.none)
fill(h0, hW, color = showZones ? color.new(cGrey, 92) : na, title = "Ranging zone")
fill(hW, hT, color = showZones ? color.new(cYellow, 90) : na, title = "Waking-up zone")
fill(hT, hS, color = showZones ? color.new(cBlue, 90) : na, title = "Trending zone")
fill(hS, hE, color = showZones ? color.new(cOrange, 88) : na, title = "Strong zone")
fill(hE, hTop, color = showZones ? color.new(cPurple, 86) : na, title = "Extreme zone")
bgcolor(highlightRange and adx < weakLvl ? color.new(cGrey, 94) : na, title = "Ranging tint")
// ───────────────────────────── PLOTS ─────────────────────────────
plot(showDI ? plusDI : na, "+DI (Buyers)", color = color.new(cGreen, 0), linewidth = 1)
plot(showDI ? minusDI : na, "-DI (Sellers)", color = color.new(cRed, 0), linewidth = 1)
plot(showGlow ? adx : na, "ADX glow", color = color.new(stateCol, 80), linewidth = 7)
plot(adx, "ADX (Trend strength)", color = stateCol, linewidth = 3)
// ───────────────────────────── SIGNALS ─────────────────────────────
okStrength = adx >= sigMin and (not requireRising or rising)
bullSig = ta.crossover(plusDI, minusDI) and okStrength
bearSig = ta.crossunder(plusDI, minusDI) and okStrength
trendStart = ta.crossover(adx, trendLvl)
// Trend peaked: ADX was very strong and has just turned down
fadeSig = adx[1] >= strongLvl and adx[1] > adx[2] and adx[1] > adx
plotshape(showSignals and bullSig, "Bullish signal", shape.triangleup, location.bottom, color.new(cGreen, 0), size = size.small, text = "UP", textcolor = cGreen)
plotshape(showSignals and bearSig, "Bearish signal", shape.triangledown, location.top, color.new(cRed, 0), size = size.small, text = "DOWN", textcolor = cRed)
// White markers so they stay visible on top of the coloured ADX line
plotshape(showSignals and trendStart ? adx : na, "Trend starts", shape.circle, location.absolute, color.white, size = size.small)
plotshape(showSignals and fadeSig ? adx[1] : na, "Trend tiring", shape.diamond, location.absolute, color.white, size = size.small, offset = -1)
alertcondition(bullSig, "Bullish trend signal", "ADX Ultimate {{ticker}} {{interval}}: buyers took control while the market has trend strength.")
alertcondition(bearSig, "Bearish trend signal", "ADX Ultimate {{ticker}} {{interval}}: sellers took control while the market has trend strength.")
alertcondition(trendStart, "Trend is starting", "ADX Ultimate {{ticker}} {{interval}}: ADX crossed above the trending level.")
alertcondition(fadeSig, "Trend is tiring", "ADX Ultimate {{ticker}} {{interval}}: a very strong trend is losing power.")
alertcondition(ta.crossunder(adx, weakLvl), "Market went ranging", "ADX Ultimate {{ticker}} {{interval}}: ADX fell below the ranging level.")
// ───────────────────────────── DASHBOARD ─────────────────────────────
dashPos = switch dashPosStr
"Top right" => position.top_right
"Bottom left" => position.bottom_left
"Bottom right" => position.bottom_right
=> position.top_left
txtSize = switch dashSizeStr
"Normal" => size.normal
"Large" => size.large
=> size.small
bigSize = switch dashSizeStr
"Normal" => size.large
"Large" => size.huge
=> size.normal
var table dash = table.new(dashPos, 2, 9, bgcolor = cDark, border_width = 1, border_color = color.new(#363A45, 40), frame_width = 1, frame_color = color.new(#363A45, 20))
// Two-column row: label + value
f_row(int r, string label, string value, color valCol) =>
table.cell(dash, 0, r, label, text_color = #9BA3B4, text_halign = text.align_left, text_size = txtSize)
table.cell(dash, 1, r, value, text_color = valCol, text_halign = text.align_left, text_size = txtSize)
// Full-width row
f_wide(int r, string txt, color txtCol, color bg, string sz) =>
table.cell(dash, 0, r, txt, text_color = txtCol, bgcolor = bg, text_halign = text.align_left, text_size = sz)
table.merge_cells(dash, 0, r, 1, r)
if dashMode != "Off" and barstate.islast
stateTxt = switch state
0 => "RANGING (no trend)"
1 => "WAKING UP"
2 => "TRENDING"
3 => "STRONG TREND"
=> "EXTREME (maybe exhausted)"
dirTxt = state == 0 ? (bull ? "▲ Buyers lead (unreliable)" : "▼ Sellers lead (unreliable)") : (bull ? "▲ BUYERS in control" : "▼ SELLERS in control")
dirCol = state == 0 ? cGrey : (bull ? cGreen : cRed)
momTxt = rising ? "↗ Rising: trend gaining power" : falling ? "↘ Falling: trend losing power" : "→ Flat: steady"
momShort = rising ? "↗ gaining power" : falling ? "↘ losing power" : "→ steady"
momCol = rising ? cGreen : falling ? cOrange : cGrey
htfLabel = "Higher TF (" + f_tfLabel(htfTf) + ")"
htfTxt = not htfOk ? "n/a (pick a higher TF)" : htfBias == 1 ? "▲ Bullish trend" : htfBias == -1 ? "▼ Bearish trend" : "Ranging / weak"
htfShort = not htfOk ? "n/a" : htfBias == 1 ? "▲ bullish" : htfBias == -1 ? "▼ bearish" : "ranging"
htfCol = htfBias == 1 ? cGreen : htfBias == -1 ? cRed : cGrey
agree = htfOk and ((bull and htfBias == 1) or (not bull and htfBias == -1))
disagree = htfOk and htfBias != 0 and not agree
// Strength meter (full bar = "extreme" level)
filled = math.min(10, math.round(nz(adx) / extremeLvl * 10))
meter = str.repeat("■", filled) + str.repeat("□", 10 - filled)
// Setup quality 0-5: strength + momentum + higher-timeframe agreement
int score = 0
if state > 0
score := state == 4 ? 2 : state
if rising
score += 1
if falling
score -= 1
if state >= 2 and agree
score += 1
if state >= 2 and disagree
score -= 1
score := math.max(0, math.min(5, score))
stars = str.repeat("★", score) + str.repeat("☆", 5 - score)
starsCol = score >= 4 ? cGreen : score == 3 ? cBlue : score == 2 ? cYellow : cGrey
// ── Suggested stance: what to do now, and what to watch next
string actTxt = ""
color actCol = cGrey
string why = ""
string nxt = ""
string sideWord = bull ? "BUYS" : "SELLS"
string dirNoun = bull ? "buyers" : "sellers"
if state == 0
actTxt := "STAND ASIDE"
actCol := cGrey
why := "No real trend: trend trades have\npoor odds here."
nxt := "Next: ADX above " + str.tostring(weakLvl) + " = a trend may form."
else if state == 1
if rising
actTxt := "GET READY"
actCol := cYellow
why := "A trend may be forming.\nDon't enter yet."
nxt := "Confirm: ADX above " + str.tostring(trendLvl) + " with " + dirNoun + " ahead."
else
actTxt := "WAIT"
actCol := cGrey
why := "Weak and fading.\nNothing to follow yet."
nxt := "Next: ADX turning back up."
else if state == 2
if disagree
actTxt := "CAUTION"
actCol := cOrange
why := "Higher timeframe opposes this move.\nLower odds."
nxt := "Safer: wait until both timeframes agree."
else
actTxt := "FAVOR " + sideWord
actCol := bull ? cGreen : cRed
why := rising ? "Trend is strengthening.\nLook for pullback entries." : falling ? "Trend is cooling.\nBe selective, trade smaller." : "Steady trend.\nLook for pullback entries."
nxt := "Exit warning: ADX turns down or\nDI lines cross back."
else
if falling
actTxt := "PROTECT PROFITS"
actCol := cOrange
why := "Trend peaked and is fading.\nAvoid new trend entries."
nxt := "Trend over if ADX drops below " + str.tostring(trendLvl) + "."
else
actTxt := "DON'T CHASE"
actCol := cOrange
why := "Mature trend: late entries get hurt.\nWait for a pullback first."
nxt := "Warning: ADX turning down = tiring."
if state >= 2 and agree
why := why + "\nHigher timeframe agrees."
whyNext = why + "\n" + nxt
if dashMode == "Full"
f_wide(0, "ADX ULTIMATE · " + syminfo.ticker + " " + f_tfLabel(timeframe.period), color.white, color.new(#2962FF, 25), txtSize)
f_row(1, "ADX value", str.tostring(adx, "#.0") + " (+DI " + str.tostring(plusDI, "#") + " / -DI " + str.tostring(minusDI, "#") + ")", stateCol)
f_row(2, "Trend strength", stateTxt + "\n" + meter, stateCol)
f_row(3, "Direction", dirTxt, dirCol)
f_row(4, "ADX momentum", momTxt, momCol)
f_row(5, htfLabel, htfTxt, htfCol)
f_row(6, "Setup quality", stars + " (" + str.tostring(score) + "/5)", starsCol)
f_wide(7, "▶ " + actTxt, color.white, color.new(actCol, 55), bigSize)
f_wide(8, whyNext, cText, color.new(actCol, 88), txtSize)
else
f_wide(0, "ADX " + str.tostring(adx, "#.0") + " · " + stateTxt + "\n" + meter, stateCol, cDark, txtSize)
f_wide(1, dirTxt + " " + momShort, dirCol, cDark, txtSize)
f_wide(2, "Setup " + stars + " HTF " + f_tfLabel(htfTf) + ": " + htfShort, cText, cDark, txtSize)
f_wide(3, "▶ " + actTxt, color.white, color.new(actCol, 55), bigSize)
f_wide(4, whyNext, cText, color.new(actCol, 88), txtSize)