Trend StrengthPine Script v6

Directional Movement Index Pine Script — Complete TradingView Guide

The Directional Movement Index (DMI) is a trend-strength system built into Pine Script v6 via ta.dmi(diLength, adxSmoothing). Developed by J. Welles Wilder Jr. in 1978, the DMI outputs three values — +DI (bullish directional movement), -DI (bearish directional movement), and ADX (Average Directional Index, measuring trend strength from 0–100) — allowing traders to determine both the direction and strength of the prevailing trend in a single indicator call. The DMI default period is 14 bars for both DI length and ADX smoothing, making it directly usable with ta.dmi(14, 14). This guide covers the complete Pine Script v6 implementation, all configurable parameters with recommended ranges, three concrete DMI trading strategies with specific entry and exit conditions, and a five-step guide to generating DMI scripts instantly with Pineify.

What Is the Directional Movement Index?

The Directional Movement Index is a trend-strength oscillator that quantifies both the direction and intensity of price movement, used to identify trending markets and generate directional entry signals. Unlike simple moving averages that only track price direction, the DMI separates directional movement into bullish (+DI) and bearish (-DI) components, then uses the Average Directional Index (ADX) to measure the overall trend strength independent of direction — making it possible to filter out low-quality signals in choppy, ranging markets.

The DMI was introduced by J. Welles Wilder Jr. in his 1978 book New Concepts in Technical Trading Systems, the same publication that also introduced the Relative Strength Index (RSI) and Average True Range (ATR). Wilder designed the DMI to answer a single question that moving averages cannot: "Is this market currently trending, and if so, how strongly?" This made the DMI especially valuable for systematic traders who needed an objective trend filter before applying directional strategies.

Core formula: The DMI begins by computing the Positive Directional Movement (+DM) and Negative Directional Movement (-DM) for each bar. If high − high[1] > low[1] − low, then +DM = high − high[1]; otherwise +DM = 0. The reverse logic applies for -DM. These values are then smoothed over the diLength period and divided by the Average True Range (ATR) to produce +DI and -DI, both scaled to 0–100. The ADX is calculated as a smoothed version of the Directional Index: DX = 100 × |+DI − −DI| ÷ (+DI + −DI), averaged over the adxSmoothing period. In Pine Script v6, the entire calculation is handled by [plusDI, minusDI, adx] = ta.dmi(14, 14).

The DMI applies to all liquid asset classes: stocks, crypto, forex, and futures. It is most effective in markets with sustained directional trends and least reliable in tight ranging environments where ADX stays below 20. Best timeframes are 1-hour, 4-hour, and Daily charts — shorter timeframes (1m, 5m) generate excessive noise in the +DI/−DI crossover signals. The ADX threshold of 25 is the widely accepted minimum for confirming a tradeable trend before acting on DMI signals.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

1H, 4H, Daily

Plot Type

Oscillator — plotted below price chart

DMI Pine Script Code Example

The code below plots all three DMI components — ADX (red), +DI (blue), and -DI (orange) — as a separate oscillator panel below the price chart using Pine Script v6. To add it to TradingView, open the Pine Script editor with Alt+P, paste the code, and click Add to chart. The ta.dmi(14, 14) call returns a tuple — adjust the first argument (DI length) and second argument (ADX smoothing) to tune responsiveness.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Directional Movement Index", overlay=false, max_labels_count=500)

// DMI — plots ADX, +DI, and -DI to measure trend strength and direction
[p_ind_1_plusDi, p_ind_1_minusDi, p_ind_1_adx] = ta.dmi(14, 14)

// Plot all three DMI lines
plot(p_ind_1_adx,     "DMI - ADX",  color.rgb(245, 0, 87, 0),   1)
plot(p_ind_1_plusDi,  "DMI - +DI",  color.rgb(41, 98, 255, 0),  1)
plot(p_ind_1_minusDi, "DMI - -DI",  color.rgb(255, 109, 0, 0),  1)

Chart Preview

Directional Movement Index indicator Pine Script code example in TradingView — ADX, +DI, and -DI lines

DMI Parameters

ParameterDefault ValueDescriptionRecommended Range
diLength14The lookback period used to smooth the Positive and Negative Directional Movement values before dividing by ATR to produce +DI and -DI. Smaller values make the DI lines more reactive to short-term price changes; larger values produce smoother, less noisy lines.7–21
adxSmoothing14The smoothing period applied to the raw Directional Index (DX) to produce the final ADX line. Controls how quickly ADX responds to changes in trend strength. Higher values produce a lag-smoothed ADX; lower values make ADX respond faster but with more whipsaws.10–20

Tuning Guide by Trading Style

  • Scalping (5m–15m charts): diLength 7–10, adxSmoothing 10 — faster DI crossovers with quicker ADX response to emerging short-term trends
  • Day trading (1H charts): diLength 14, adxSmoothing 14 — Wilder's original default, well-calibrated for intraday directional signals
  • Swing trading (4H–Daily charts): diLength 14, adxSmoothing 20 — smoother ADX that reduces false trend confirmations in multi-day swing setups

DMI Trading Strategies

The DMI is most effective as a trend-confirmation filter and directional crossover signal generator. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — +DI/−DI Crossover with ADX Filter

Market environment: trending markets · Best timeframe: 1H, 4H, Daily

The +DI/−DI crossover is the primary DMI trading signal. When +DI crosses above -DI while ADX is above 25, it confirms a bullish trend with sufficient strength. Use ta.crossover(plusDI, minusDI) in Pine Script to detect the crossover.

  1. Calculate DMI: [plusDI, minusDI, adx] = ta.dmi(14, 14)
  2. Long entry: ta.crossover(plusDI, minusDI) AND adx > 25 — directional shift confirmed by trend strength
  3. Confirm price is above its 50-period EMA to avoid counter-trend longs
  4. Short entry: ta.crossunder(plusDI, minusDI) AND adx > 25
  5. Exit: opposite DI crossover OR ADX drops below 20 (trend is losing strength)

Strategy 2 — ADX Trend Strength Filter for Breakouts

Market environment: breakout from consolidation · Best timeframe: Daily

ADX rising from below 20 to above 25 signals that a new trend is forming after a consolidation period. Pairing this ADX expansion signal with a Bollinger Band squeeze breakout generates high-probability trend-entry setups — the Bollinger Band confirms price is breaking out while ADX confirms the breakout has directional momentum.

  1. Calculate DMI: [plusDI, minusDI, adx] = ta.dmi(14, 14)
  2. Condition 1 (ADX expansion): adx > 25 AND adx > adx[1] — ADX is rising, confirming new trend
  3. Condition 2 (direction): plusDI > minusDI for long, minusDI > plusDI for short
  4. Condition 3 (entry trigger): close crosses above upper Bollinger Band (20, 2.0) for long breakout confirmation
  5. Exit: ADX falls below 20 (trend exhaustion) OR price closes back inside Bollinger Bands for 2 consecutive bars

Strategy 3 — DMI + RSI Divergence Confirmation

Market environment: trending markets with pullback entries · Best timeframe: 4H, Daily

Pairing DMI's trend direction signal with RSI(14) momentum confirmation reduces false entries during brief pullbacks. ADX above 25 confirms the trend is valid, while RSI above 50 confirms bullish momentum before entering long.

  1. Calculate DMI: [plusDI, minusDI, adx] = ta.dmi(14, 14)
  2. Calculate momentum: rsi14 = ta.rsi(close, 14)
  3. Long entry: plusDI > minusDI AND adx > 25 AND rsi14 > 50
  4. Avoid: entries where rsi14 > 70 (overbought — momentum may be exhausted)
  5. Exit: minusDI crosses above plusDI OR ADX falls below 20 OR rsi14 drops below 45

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate the DMI Indicator in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account is sufficient to generate DMI indicators with full Pine Script v6 code.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation menu on the dashboard to start a new Pine Script project.

  3. 3

    Describe the DMI configuration you want

    Type a prompt such as: "Plot the Directional Movement Index with ADX, +DI, and -DI lines using ta.dmi(14, 14). Color ADX red, +DI blue, -DI orange." Pineify's AI Coding Agent generates the complete Pine Script v6 code in seconds.

  4. 4

    Copy to TradingView

    Click "Copy to TradingView" to copy the generated code, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart" to see all three DMI lines.

  5. 5

    Adjust the diLength and adxSmoothing parameters

    In the TradingView indicator settings panel, change the DI length and ADX smoothing (e.g., from 14 to 7 for faster signals) to match your trading timeframe — no code editing required.

Frequently Asked Questions

Build Your DMI Indicator in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including DMI with ADX trend filters and +DI/−DI crossover strategies — instantly for free.

Try Pineify Free