ta.dmi()Directional Movement Index (DMI & ADX)
ta.dmi(diLength, adxSmoothing) calculates the Directional Movement Index and Average Directional Index (ADX) in Pine Script v5 and v6. It returns a 3-element tuple: [diPlus, diMinus, adx]. TradingView does not provide a standalone ta.adx() function; ADX is obtained directly as the third value of the ta.dmi() tuple.
Pine Script v6 reference verified: · TradingView reference
Syntax
ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]Arguments
| Parameter | Type | Description |
|---|---|---|
| diLength | simple int | Required DI calculation period. Accepts a positive simple int or an input.int value. The examples use 14; the function has no default argument. |
| adxSmoothing | simple int | Required ADX smoothing period. Accepts a positive simple int or an input.int value. It can differ from diLength; the examples use 14. |
Returns
Tuple of three series float values: [diPlus, diMinus, adx]. diPlus is Plus Directional Indicator (+DI), diMinus is Minus Directional Indicator (-DI), and adx is Average Directional Index (ADX).
Remarks
The function returns a 3-element tuple ([diPlus, diMinus, adx]), not an array. TradingView Pine Script has no standalone ta.adx() function; calling ta.adx() fails because the compiler cannot find that built-in function. In both Pine Script v5 and v6, unpack the tuple using [diPlus, diMinus, adx] = ta.dmi(14, 14). To reference prior bar values, apply the history-referencing operator [] to individual unpacked series (e.g., adx[1]), never to the tuple-returning call. DI and ADX values can change on an open bar. The v6 example marks qualifying crosses only when the chart bar closes. These are educational indicators, not a backtested strategy or investment advice.
Check DMI parameters before changing your signal
Supply both lengths, unpack the three values in order, and use the ADX series in your condition. A syntax pass checks compilation; it does not establish whether a threshold works for your market. The examples below have not been backtested for profitability.
The first example preserves Pine Script v5 syntax. The second uses v6 and waits for the chart bar to close before marking a cross. Compare their DI and ADX plots with TradingView's built-in DMI using the same symbol, timeframe, DI length, and ADX smoothing.
Read TradingView's DMI settings and threshold explanation and higher-timeframe repainting guidance.
For a larger script, the Pine Script AI Coding Agent can help revise the DMI call and surrounding conditions. Include your Pine version and compiler message. Browse TradingView coding guides for related syntax issues.
Code Examples
//@version=5
indicator("Pine Script v5 ta.dmi Signature & ADX Example", shorttitle="v5 DMI/ADX", overlay=false)
// Define parameters
diLen = input.int(14, title="DI Length", minval=1)
adxSmooth = input.int(14, title="ADX Smoothing", minval=1)
// Function signature: ta.dmi(diLength, adxSmoothing) -> [series float, series float, series float]
// TradingView has no ta.adx() built-in; extract ADX as the 3rd tuple element
[diPlus, diMinus, adx] = ta.dmi(diLen, adxSmooth)
// Plot ADX line and DI directional lines
plot(adx, title="ADX", color=color.red, linewidth=2)
plot(diPlus, title="+DI", color=color.green, linewidth=1)
plot(diMinus, title="-DI", color=color.purple, linewidth=1)
hline(25, title="Key Level (25)", color=color.gray, linestyle=hline.style_dashed)//@version=6
indicator("DMI & ADX Signal Filter", shorttitle="DMI / ADX", overlay=false)
diLength = input.int(14, title="DI Length", minval=1)
adxSmoothing = input.int(14, title="ADX Smoothing", minval=1)
adxThreshold = input.float(25.0, title="ADX Trend Filter Threshold")
// Destructure the [diPlus, diMinus, adx] tuple
[diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
// Evaluate both crosses on every bar before applying the closing-bar filter.
diCrossUp = ta.crossover(diPlus, diMinus)
diCrossDown = ta.crossunder(diPlus, diMinus)
bullishCross = diCrossUp and adx > adxThreshold and barstate.isconfirmed
bearishCross = diCrossDown and adx > adxThreshold and barstate.isconfirmed
plot(adx, title="ADX", color=color.red, linewidth=2)
plot(diPlus, title="+DI", color=color.blue, linewidth=1)
plot(diMinus, title="-DI", color=color.orange, linewidth=1)
hline(adxThreshold, title="Threshold", color=color.gray, linestyle=hline.style_dashed)
plotshape(bullishCross, title="Bullish Signal", style=shape.triangleup, location=location.bottom, color=color.green, size=size.small)
plotshape(bearishCross, title="Bearish Signal", style=shape.triangledown, location=location.top, color=color.red, size=size.small)Trading Applications
Measure trend strength with ADX regardless of bullish or bearish direction
Observe changes in directional bias through +DI and -DI crossovers
Test an ADX threshold as a trade filter; it does not eliminate false breakouts
Combine with RSI or moving averages to build trend-following strategies
Related Functions
Frequently Asked Questions
Generate ta.dmi() Code with AI
Draft Pine Script using ta.dmi() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
Related Pine Script Functions
ta.macd() - MACD
Learn how to use ta.macd() in Pine Script. Syntax, parameters, code examples for MACD line, signal line, and histogram.
ta.supertrend() - Supertrend
Learn how to use ta.supertrend() in Pine Script. Syntax, parameters, code examples for the ATR-based trend overlay.
ta.sar() - Parabolic SAR
Learn how to use ta.sar() in Pine Script. Syntax, parameters, code examples for the Parabolic Stop and Reverse indicator.
ta.rsi() - Relative Strength Index
Learn how to use ta.rsi() in Pine Script. Syntax, parameters, code examples for the RSI momentum oscillator.
ta.atr() - Average True Range
Learn how to use ta.atr() in Pine Script. Syntax, parameters, code examples for the Average True Range volatility indicator.