Indicator · Pine Script v6 · Own pane

ADX and DI

by rubbermetal· code credited to claygrace74

A separate-pane indicator that calculates the Average Directional Index and the plus and minus directional indicators with Wilder-style smoothing over an adjustable length.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code102
Settings10inputs
LicenceMPL-2.0
Last update4 months ago10 Jun 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

102 lines of Pine Script v6 from ADX and DI.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

ADX and DI.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © claygrace74

//@version=6
indicator("ADX and DI", shorttitle="ADX/DI")

// ==================== ADX Settings ====================
var adx_group = "ADX Settings"
len = input.int(14, "Length", minval=1, group=adx_group)

// ==================== Display Settings ====================
var disp_group = "Display Settings"
i_showDIPlus      = input.bool(true,  "Show DI+", group=disp_group)
i_showDIMinus     = input.bool(true,  "Show DI-", group=disp_group)
i_showDIFill      = input.bool(true,  "Show DI+/DI- Fill", group=disp_group)
i_showCrossSignals = input.bool(true, "Show DI Cross Signals", group=disp_group)
i_showStrength    = input.bool(true,  "Show Trend Strength Label", group=disp_group)
i_bullColor       = input.color(color.green, "Bullish Color (DI+)", group=disp_group)
i_bearColor       = input.color(color.red,   "Bearish Color (DI-)", group=disp_group)

// ==================== Zone Settings ====================
var zone_group = "Zone Settings"
th       = input.int(25, "Weak/Strong Threshold", minval=0, maxval=100, group=zone_group)
strongTh = input.int(50, "Strong Trend Threshold", minval=0, maxval=100, group=zone_group)

// ==================================================================================
// Core Calculations (Wilder Smoothing)
// ==================================================================================
TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
DirectionalMovementPlus  = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

float SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1]) / len) + TrueRange

float SmoothedDMPlus = 0.0
SmoothedDMPlus := nz(SmoothedDMPlus[1]) - (nz(SmoothedDMPlus[1]) / len) + DirectionalMovementPlus

float SmoothedDMMinus = 0.0
SmoothedDMMinus := nz(SmoothedDMMinus[1]) - (nz(SmoothedDMMinus[1]) / len) + DirectionalMovementMinus

DIPlus  = SmoothedDMPlus  / SmoothedTrueRange * 100
DIMinus = SmoothedDMMinus / SmoothedTrueRange * 100
DX  = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX = ta.sma(DX, len)

// Direction and signals
bullish    = DIPlus > DIMinus
diCrossUp  = ta.crossover(DIPlus, DIMinus)
diCrossDown = ta.crossunder(DIPlus, DIMinus)
adxRising  = ta.change(ADX) > 0

// Trend strength category
strengthText  = ADX >= 75 ? "EXTREME" : ADX >= strongTh ? "STRONG" : ADX >= th ? "TRENDING" : "NO TREND"
strengthColor = ADX >= 75 ? color.new(color.orange, 0) : ADX >= strongTh ? color.new(color.yellow, 0) : ADX >= th ? color.new(i_bullColor, 30) : color.new(color.gray, 30)

// ==================================================================================
// Grid Layout
// ==================================================================================
h100    = hline(100, "100", color=color.new(color.gray, 80), linestyle=hline.style_solid)
hStrong = hline(strongTh, "Strong Threshold", color=color.new(color.gray, 50), linestyle=hline.style_dashed)
hWeak   = hline(th,       "Weak/Strong Threshold", color=color.new(color.gray, 50), linestyle=hline.style_solid)
h0      = hline(0,   "0",   color=color.new(color.gray, 80), linestyle=hline.style_solid)

// Zone fills
fill(h0, hWeak,      color=color.new(color.green, 92))   // No trend zone (safe)
fill(hStrong, h100,  color=color.new(color.orange, 92))   // Extreme zone (warning)

// ==================================================================================
// Plots
// ==================================================================================

// DI+ and DI- lines with fill
pPlus  = plot(i_showDIPlus  ? DIPlus  : na, "DI+", color=color.new(i_bullColor, 30), linewidth=1)
pMinus = plot(i_showDIMinus ? DIMinus : na, "DI-", color=color.new(i_bearColor, 30), linewidth=1)
fill(pPlus, pMinus, color=i_showDIFill ? (bullish ? color.new(i_bullColor, 85) : color.new(i_bearColor, 85)) : color(na), title="DI Fill")

// ADX line — gradient colored by value, green/red tint by DI direction
adxColor = bullish ? color.from_gradient(ADX, 0, 75, color.new(i_bullColor, 70), i_bullColor) : color.from_gradient(ADX, 0, 75, color.new(i_bearColor, 70), i_bearColor)
plot(ADX, "ADX", color=adxColor, linewidth=2)

// DI cross signals
plotshape(i_showCrossSignals and diCrossUp,   style=shape.triangleup,   location=location.bottom, color=i_bullColor, text="DI+", textcolor=i_bullColor, size=size.tiny, title="DI+ Cross Up")
plotshape(i_showCrossSignals and diCrossDown, style=shape.triangledown, location=location.top,    color=i_bearColor, text="DI-", textcolor=i_bearColor, size=size.tiny, title="DI- Cross Down")

// ==================================================================================
// Trend Strength Label
// ==================================================================================
var tbl = table.new(position.top_right, 1, 1, bgcolor=color.new(color.black, 50), border_width=1, border_color=color.new(color.gray, 50))

if i_showStrength and barstate.islast
    table.cell(tbl, 0, 0, strengthText + " (" + str.tostring(ADX, "#.0") + ")", bgcolor=strengthColor, text_color=color.white, text_size=size.small)

// ==================================================================================
// Alert Conditions
// ==================================================================================
alertcondition(diCrossUp,                          "DI+ Crosses Above DI-",   "DI+ crossed above DI- — potential bullish signal")
alertcondition(diCrossDown,                        "DI+ Crosses Below DI-",   "DI+ crossed below DI- — potential bearish signal")
alertcondition(ta.crossover(ADX, th),              "ADX Above Threshold",     "ADX crossed above weak/strong threshold — trend strengthening")
alertcondition(ta.crossunder(ADX, th),             "ADX Below Threshold",     "ADX crossed below weak/strong threshold — trend weakening")
alertcondition(ADX > strongTh and adxRising,       "Strong Trend Intensifying","ADX above strong threshold and rising")
alertcondition(diCrossUp and ADX > th,             "Confirmed Bullish Entry", "DI+ crossed DI- with ADX confirming trend strength")

Overview

ADX and DI plots ADX with grid lines at weak, strong and extreme levels, optional DI+ and DI- lines with a fill between them, and optional markers where the two DI lines cross. A text label classifies trend strength as no trend, trending, strong or extreme using the thresholds. Colours and thresholds are adjustable. It does not create trade orders.

Details

Published by

rubbermetal on GitHub

Code credit

claygrace74, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lengthint14len
Show DI+booltruei_showDIPlus
Show DI-booltruei_showDIMinus
Show DI+/DI- Fillbooltruei_showDIFill
Show DI Cross Signalsbooltruei_showCrossSignals
Show Trend Strength Labelbooltruei_showStrength
Bullish Color (DI+)colorcolor.greeni_bullColor
Bearish Color (DI-)colorcolor.redi_bearColor
Weak/Strong Thresholdint25th
Strong Trend Thresholdint50strongTh
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 11 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers