TrendPine Script v6

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

Syntax
ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]

Arguments

ParameterTypeDescription
diLengthsimple intRequired DI calculation period. Accepts a positive simple int or an input.int value. The examples use 14; the function has no default argument.
adxSmoothingsimple intRequired 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

Pine Script v5: ta.dmi Signature & ADX Extraction
//@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)
Pine Script v6: DMI Trend Filter & Cross Signals
//@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

Frequently Asked Questions

In both Pine Script v5 and v6, the signature is ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]. It accepts two simple int parameters (diLength and adxSmoothing) and returns a 3-element tuple: [diPlus, diMinus, adx]. You unpack the tuple into three separate series variables using tuple destructuring: [diPlus, diMinus, adx] = ta.dmi(14, 14).

No. Pine Script does not have a standalone ta.adx() built-in function in v5 or v6. Calling ta.adx(14, 14) fails because the compiler cannot find that function. To retrieve ADX, call ta.dmi(diLength, adxSmoothing) and extract the third value from the returned tuple: [diPlus, diMinus, adx] = ta.dmi(14, 14). If you only need ADX and want to discard the DI lines, you still destructure the tuple: [_, _, adx] = ta.dmi(14, 14).

ta.dmi() requires two arguments: diLength (simple int) and adxSmoothing (simple int). diLength controls the DI calculation period; adxSmoothing controls the ADX smoothing period. Both arguments are required and can have different values. TradingView's built-in DMI indicator defaults both settings to 14, but ta.dmi() does not supply either argument automatically.

In Pine Script, square brackets [] are the history-referencing operator, not a zero-based array or tuple index. Calling ta.dmi(14, 14)[1] attempts to reference the previous bar's tuple, which is invalid syntax. You must first destructure the tuple into named series variables with [diPlus, diMinus, adx] = ta.dmi(14, 14), then apply the history-referencing operator to the specific series you need, such as adx[1] or diPlus[1].

+DI and -DI describe directional movement, while ADX measures trend strength without specifying direction. Wilder's commonly cited levels are above 25 for a strong trend and below 20 for a weak trend; the interval between them is inconclusive. These are conventions to evaluate for the market and timeframe, not guarantees of a reversal or a profitable trade.

Yes. request.security() can return all three series from a ta.dmi() call. When requesting a higher timeframe, values from its open bar can change and repaint after a reload. Setting gaps or lookahead alone does not make them confirmed. For confirmed values, return the previous higher-timeframe bar's three individual series from a helper function and use lookahead = barmerge.lookahead_on. This deliberately delays the values by one higher-timeframe bar.

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.