Indicator TutorialPine Script v6

ADX indicator: trend strength vs direction

ADX can rise during a price decline. Read +DI and -DI separately to assess direction.

The Average Directional Index measures trend strength on a 0 to 100 scale. It does not tell you to buy or sell. On TradingView, add ADX for the strength line alone or Directional Movement (DMI) for ADX, +DI and -DI together. Use the examples below to distinguish a high reading, a rising line and a directional crossover before adding an ADX filter to your own rules.

What is ADX, and which TradingView study should you add?

Open Indicators on your chart and search for Average Directional Index or Directional Movement. Select the built-in study. TradingView's ADX documentation confirms that its ADX study does not show the DI lines; DMI shows all three. An ADX/DMI indicator comparison is therefore partly a choice of which lines you need to see.

Use ADX to describe strength and compare +DI with -DI for directional pressure. +DI above -DI indicates greater upward directional movement; the reverse indicates greater downward movement. Neither relationship measures the probability that the next trade wins.

Before comparing two charts, match the symbol, session, timeframe, DI length and ADX smoothing. Fourteen bars means fourteen chart observations, not necessarily fourteen days. Explore the TradingView indicators directory for related studies. The ta.dmi reference covers the function signature and compiler details.

Why Traders Use This Indicator

  • Separate the strength of recent directional movement from its direction.
  • Define a measurable filter for an existing entry rule.
  • Compare how often the same rule triggers in different market conditions.
ParameterDefaultDescription
DI length14Controls smoothing of directional movement and true range. Shortening it makes the DI comparison more responsive; changing it also changes the DX series feeding ADX.
ADX smoothing14Controls averaging of DX. A longer length reduces the weight of each new DX value and usually makes strength changes slower to appear.
Strength threshold25 in this exampleA rule threshold, not a calculation setting. Changing it changes which events qualify without changing the ADX line.
Reference level20 in this exampleA visual comparison level only. The example does not turn low ADX into a range-trading signal.

How directional movement becomes a strength reading

For consecutive bars, define up = high - high[1] and down = low[1] - low. Set +DM = up only when up is positive and greater than down; otherwise use zero. Set -DM = down only when down is positive and greater than up. A tie gives zero to both. There is no extra price threshold in these rules.

True range is max(high - low, abs(high - close[1]), abs(low - close[1])). Smooth DM and true range with Wilder averaging, then compute +DI = 100 × smoothed(+DM) / smoothed(TR) and the equivalent -DI. For a positive DI sum, DX = 100 × abs(+DI - -DI) / (+DI + -DI). ADX is a smoothed DX series. The script uses the built-in calculation to retain its initialization and zero-denominator handling.

TradingView's DMI documentation describes the movement rules and default lengths. A larger ADX smoothing length gives the newest DX value less weight. It does not add directional information.

Signal Interpretation

Read level, slope and direction separately

The following readings are hypothetical snapshots, not historical data or backtest results. They show why one ADX number cannot define an entry.

SnapshotADX / prior ADX+DI / -DIInterpretation
Upward movement32 / 2930 / 12Strength rises while +DI dominates.
Downward movement32 / 2912 / 30The same ADX readings can accompany a decline.
Fading strength32 / 3628 / 16ADX stays high while falling. This alone does not identify a reversal.
Low strength17 / 1822 / 21Direction is narrowly positive, but the ADX filter below rejects the event.

Levels 20 and 25 are conventional reference points, not validated optima for every market. A 20 threshold admits a reading of 23; a 25 threshold rejects it. Requiring ADX to rise is a separate rule: it would reject the fading-strength snapshot even though 32 exceeds both thresholds.

What the example actually marks

A long-side observation requires +DI to cross above -DI and ADX to meet the selected threshold on that same closed bar. The short-side observation mirrors the crossover. There is no rising-ADX requirement. If a DI cross occurs at ADX 23 and ADX reaches 25 on the next bar, the script does not create a delayed event. A persistent filter such as +DI > -DI and ADX >= 25 would be a different rule.

ADX and DI can change during an open bar. This script waits for barstate.isconfirmed before marking or alerting. That introduces a wait until bar close; it does not predict that a cross will hold afterward. See TradingView's repainting documentation.

To receive notifications, create an alert in TradingView. TradingView stores a snapshot of the script and inputs, so recreate the alert after changing them. Documentation checked October 16, 2026.

Combining with Other Indicators

For an existing breakout or moving-average strategy, treat ADX as an additional condition and preserve the original entry, exit, sizing and cost assumptions. Compare the unfiltered strategy with the filtered version. A filter can remove losing entries and winning entries; fewer trades do not establish better performance.

Price structure can define direction while ADX supplies a strength condition. DI is optional in that arrangement. ATR answers a different question, recent range size; a high ATR does not establish a directional trend. See the ATR settings guide for that distinction.

Once an order-executing strategy exposes the threshold and lengths as inputs, Strategy Optimizer can compare parameter combinations. The indicator below does not place orders or produce strategy performance metrics.

Writing Pine Script Manually

Challenges of Manual Coding

Applying different conditions to plotted markers and alerts.

Mistaking a DI crossing event for a persistent direction condition.

Comparing different smoothing lengths and attributing the difference to the threshold.

Using an unfinished chart bar as if its ADX and DI values were final.

Pine Script v6
//@version=6
indicator("ADX strength and DI events", shorttitle="ADX rules", overlay=false, precision=2)

diLength = input.int(14, "DI length", minval=1)
adxSmoothing = input.int(14, "ADX smoothing", minval=1)
strengthLevel = input.float(25.0, "Strength threshold", minval=0, maxval=100, step=1)

[plusDI, minusDI, adxValue] = ta.dmi(diLength, adxSmoothing)

// Calculate crosses every bar; markers and alerts share the confirmed events.
upCross = ta.crossover(plusDI, minusDI)
downCross = ta.crossunder(plusDI, minusDI)
longEvent = barstate.isconfirmed and upCross and adxValue >= strengthLevel
shortEvent = barstate.isconfirmed and downCross and adxValue >= strengthLevel

plot(adxValue, "ADX", color=color.purple, linewidth=2)
plot(plusDI, "+DI", color=color.teal)
plot(minusDI, "-DI", color=color.orange)
hline(strengthLevel, "Strength threshold", color=color.gray)
hline(20, "20 reference only", color=color.new(color.gray, 60))
plotshape(longEvent, title="Confirmed +DI cross", style=shape.triangleup, location=location.bottom, color=color.teal, size=size.tiny)
plotshape(shortEvent, title="Confirmed -DI cross", style=shape.triangledown, location=location.top, color=color.orange, size=size.tiny)

alertcondition(longEvent, "Confirmed +DI cross with ADX filter", "+DI crossed above -DI with ADX meeting the threshold on {{ticker}} at bar close.")
alertcondition(shortEvent, "Confirmed -DI cross with ADX filter", "-DI crossed above +DI with ADX meeting the threshold on {{ticker}} at bar close.")

Maintenance Note: This educational indicator marks observations, not trade orders. Lines update intrabar; markers and alert conditions wait for chart-bar close. It uses the chart timeframe, no higher-timeframe requests and no backdated markers. Data revisions can still change history. Syntax validity does not establish profitability.

Build with Pineify Visual Editor

Pineify lets you configure supported indicators and export Pine Script. Available settings and plan requirements vary by indicator. Compare the generated rules with the example before using its signals.

FeatureManual Pine ScriptPineify Visual Editor
DMI inputsSet DI length and ADX smoothing in the script.Configure both inputs in the DMI module.
OutputsPlot the three values returned by ta.dmi.Use the DMI module outputs for +DI, -DI and ADX.
Custom rulesWrite the crossover and confirmation conditions.Configure supported conditions or ask the AI Coding Agent for the specified rule.
ValidationCheck values and event timing in TradingView.Review the generated code and perform the same chart checks.

Set DI length and ADX smoothing through the visual DMI module.

Use ADX as a condition alongside an existing entry rule.

Ask the AI Coding Agent for a custom bar-close filter, then inspect its output.

Step-by-Step Tutorial

1

Create an indicator project

Open the Pineify Visual Editor and start an indicator.

2

Add Directional Movement Index

Use DI Length 14 and ADX Smoothing 14 as a baseline.

3

Choose outputs and rules

Plot ADX, +DI and -DI. Specify whether your condition is a crossing event or a persistent state. Request custom confirmation logic from the AI Coding Agent when needed.

4

Inspect the exported script

Check the inputs, marker conditions and alert conditions before compiling in TradingView.

5

Compare matching studies

Compare closed-bar values against built-in DMI with the same symbol, session, timeframe and lengths. Review several bars after initialization.

Trading Strategies & Pro Tips

Threshold sensitivity: 20, 25 and 30

Hold both lengths at 14 and compare the same DI events at each threshold. Count accepted and rejected events. For an existing strategy, also compare trade count, net results after costs and drawdown with the filter off.

Pro Tip: This is a proposed experiment, not a reported test. Keep entries, exits, costs, symbol, session and timeframe fixed.

Separate the two smoothing controls

First hold DI length at 14 and compare ADX smoothing of 7, 14 and 28. Then hold ADX smoothing at 14 and vary DI length. Record changes in event count and timing before combining parameter changes.

Pro Tip: These input values are illustrative candidates. A faster response can also admit more short-lived changes.

Compare trend and range samples

Choose sample dates before tuning, including directional advances, declines and sideways periods. Use the same rules across all samples, retain a later untouched period, and report results by period rather than only the pooled total.

Pro Tip: High ADX can persist after a sharp move. Low ADX does not guarantee that price will remain in a range.

Common Mistakes to Avoid

  • Reading a rising ADX line as a bullish price signal.
  • Treating falling ADX as proof of a reversal or a safe range trade.
  • Calling ADX above 25 statistically significant without a statistical test.
  • Adding a delayed marker when the threshold is reached after the DI cross.
  • Selecting settings on the same sample used to claim success.

Frequently Asked Questions

ADX describes trend strength. It contains no bullish or bearish sign, so a rising reading can accompany either an advance or a decline. Direction needs a separate observation such as the DI relationship or a price rule.

The built-in ADX study displays the strength line alone. Directional Movement (DMI) displays ADX with +DI and -DI. Add DMI when you need all three and match its lengths before comparing values.

Neither is established as universally better. Lowering the threshold admits more of the same candidate events; raising it excludes more. Compare a fixed entry rule at several thresholds, including no filter, with costs and untouched data.

No. It means the smoothed strength reading has declined. Price can continue in the same direction while ADX falls. Examine direction separately and keep an explicit exit rule.

ADX and DI lines change on the open chart bar. Markers and alert conditions require barstate.isconfirmed, so they wait for bar close. The script makes no higher-timeframe requests and does not backdate markers. Historical data revisions remain possible.

The example is an indicator and produces no strategy trades. First define an order-executing strategy with entries, exits, sizing, costs and exposed inputs. Then compare parameter combinations and validate the chosen settings on data not used for tuning.

Add an explicit ADX filter to your rules

  • Configure the DMI lengths and outputs in the Visual Editor.
  • Describe custom event and confirmation rules to the AI Coding Agent.
  • Inspect the script and compare filtered results before relying on it.

Disclaimer: Trading involves significant risk. The indicators, code, and strategies provided are for educational purposes only and do not constitute financial advice. Past performance is not indicative of future results.