Indicator · Pine Script v6 · Own pane

ADX Trend Filter Pro

by rehanqx· code credited to RehanFX_Alpha | MUHAMMAD REHAN AFZAL

ADX Trend Filter Pro is a separate-pane indicator built on the directional movement system.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code217
Settings12inputs
LicenceMPL-2.0
Last update4 months ago15 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

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

ADX_AlphaEdition.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RehanFX_Alpha | MUHAMMAD REHAN AFZAL
//@version=6
indicator("ADX Trend Filter Pro [Alpha Edition]", shorttitle="ADX Pro [Alpha]")

// ═══════════════════════════════════════════════════════
//  ADX TREND FILTER PRO — Alpha EDITION
//  Enhancements:
//    • Customizable ADX/EMA inputs
//    • Trend Strength levels (Weak/Moderate/Strong/Very Strong)
//    • ADX Divergence detection
//    • Trend Weakening alert
//    • Full info table with actual values
//    • Gradient histogram colors
//    • Signal quality filter
// ═══════════════════════════════════════════════════════

// ─── INPUTS ─────────────────────────────────────────────

grp_adx = "📐 ADX Settings"
adx_len      = input.int(14,  "ADX Length",          group=grp_adx)
adx_smooth   = input.int(14,  "ADX Smoothing",       group=grp_adx)
adx_weak     = input.int(20,  "Weak Threshold",      group=grp_adx)
adx_mod      = input.int(30,  "Moderate Threshold",  group=grp_adx)
adx_strong   = input.int(40,  "Strong Threshold",    group=grp_adx)

grp_ema = "📈 EMA Settings"
ema_fast_len = input.int(12, "Fast EMA", group=grp_ema)
ema_slow_len = input.int(50, "Slow EMA", group=grp_ema)

grp_sig = "🎯 Signal Settings"
only_strong  = input.bool(false, "Only Strong Trend Signals (ADX > Moderate)", group=grp_sig)
show_div     = input.bool(true,  "Show Divergence Warning",                     group=grp_sig)

grp_disp = "🖥️ Display"
txtcol       = input.color(color.gray, "Text Color",  group=grp_disp)
show_table   = input.bool(true,  "Show Info Table",   group=grp_disp)
show_signals = input.bool(true,  "Show Buy/Sell Signals", group=grp_disp)

// ─── CORE CALCS ──────────────────────────────────────────

[di_plus, di_minus, adx] = ta.dmi(adx_len, adx_smooth)
ema_fast = ta.ema(close, ema_fast_len)
ema_slow = ta.ema(close, ema_slow_len)

// ─── TREND STRENGTH ──────────────────────────────────────

strength_txt = adx >= adx_strong ? "VERY STRONG 🔥" :
               adx >= adx_mod    ? "STRONG 💪"      :
               adx >= adx_weak   ? "MODERATE ⚡"    : "WEAK 😴"

strength_col = adx >= adx_strong ? color.rgb(255, 50,  50)  :
               adx >= adx_mod    ? color.rgb(255, 140, 0)   :
               adx >= adx_weak   ? color.rgb(255, 220, 0)   :
                                   color.rgb(120, 120, 120)

// ─── DIRECTION ───────────────────────────────────────────

bull_bias  = di_plus  > di_minus
bear_bias  = di_minus > di_plus
is_ranging = adx < adx_weak

// ─── EMA TREND ───────────────────────────────────────────

ema_bull  = ema_fast > ema_slow
ema_bear  = ema_fast < ema_slow
ema_color = ema_bull ? color.rgb(79, 163, 81) : color.rgb(77, 23, 28)

// ─── ADX DIVERGENCE ──────────────────────────────────────
// Price making higher highs but ADX falling = weak trend

price_hh  = high > high[1] and high[1] > high[2]
adx_fall  = adx  < adx[1]  and adx[1]  < adx[2]
price_ll  = low  < low[1]  and low[1]  < low[2]
adx_rise  = adx  > adx[1]  and adx[1]  > adx[2]

bull_div  = price_hh and adx_fall and bull_bias   // price up, ADX down = weakening bull
bear_div  = price_ll  and adx_fall and bear_bias  // price down, ADX down = weakening bear

// ─── SIGNAL QUALITY FILTER ───────────────────────────────

signal_ok = only_strong ? adx >= adx_mod : adx >= adx_weak

buy_signal  = ta.crossover(di_plus, di_minus)  and bull_bias and signal_ok
sell_signal = ta.crossunder(di_plus, di_minus) and bear_bias and signal_ok

// ─── GRADIENT HISTOGRAM ──────────────────────────────────
// Stronger ADX = more saturated color

bull_intensity = math.min(adx / adx_strong, 1.0)
bear_intensity = math.min(adx / adx_strong, 1.0)

bull_col = color.from_gradient(bull_intensity, 0, 1, color.rgb(100, 200, 100), color.rgb(0, 120, 0))
bear_col = color.from_gradient(bear_intensity, 0, 1, color.rgb(200, 100, 100), color.rgb(140, 0, 0))

// ─── PLOTS ───────────────────────────────────────────────

// ADX area background
plot(adx, "ADX", style=plot.style_area, color=color.new(color.red, 70))

// DI+ / DI- histogram with gradient
plot(di_plus,  "DI+", color=bull_bias ? bull_col : color.new(color.green, 60), style=plot.style_columns)
plot(di_minus, "DI-", color=bear_bias ? bear_col : color.new(color.red,   60), style=plot.style_columns)

// MA Band at threshold level
plot(adx_weak, title="MA BAND", style=plot.style_area, color=ema_color)

// ADX line on top
plot(adx, "ADX Line", color=strength_col, linewidth=2)

// ─── BAR COLOR ───────────────────────────────────────────

barcolor(bull_bias and adx > adx_weak ? color.rgb(4, 104, 1)   :
         bear_bias and adx > adx_weak ? color.rgb(163, 2, 2)   :
         color.rgb(247, 222, 4))

// ─── SIGNALS ─────────────────────────────────────────────

if show_signals
    if buy_signal
        label.new(bar_index, di_minus - 2, "▲ BUY",
             style=label.style_label_up,
             color=color.new(color.green, 10),
             textcolor=color.white,
             size=size.tiny)
    if sell_signal
        label.new(bar_index, di_plus + 2, "▼ SELL",
             style=label.style_label_down,
             color=color.new(color.red, 10),
             textcolor=color.white,
             size=size.tiny)

// ─── DIVERGENCE WARNING ──────────────────────────────────

if show_div
    if bull_div
        label.new(bar_index, adx + 3, "⚠ DIV",
             style=label.style_label_down,
             color=color.new(color.orange, 20),
             textcolor=color.white,
             size=size.tiny)
    if bear_div
        label.new(bar_index, adx + 3, "⚠ DIV",
             style=label.style_label_down,
             color=color.new(color.orange, 20),
             textcolor=color.white,
             size=size.tiny)

// ─── ALERTS ──────────────────────────────────────────────

alertcondition(buy_signal,                    "▲ ADX Buy Signal",      "ADX Buy — DI+ crossed above DI-")
alertcondition(sell_signal,                   "▼ ADX Sell Signal",     "ADX Sell — DI- crossed above DI+")
alertcondition(adx >= adx_strong,             "🔥 Very Strong Trend",  "ADX Very Strong — momentum building")
alertcondition(adx < adx_weak and adx[1] >= adx_weak, "😴 Trend Weakening", "ADX dropped below threshold — ranging market")
alertcondition(bull_div,                      "⚠ Bull Divergence",     "Price HH but ADX falling — bull trend weakening")
alertcondition(bear_div,                      "⚠ Bear Divergence",     "Price LL but ADX falling — bear trend weakening")
alertcondition(ema_bull and not ema_bull[1],  "EMA Bullish Cross",     "EMA Fast crossed above Slow")
alertcondition(ema_bear and not ema_bear[1],  "EMA Bearish Cross",     "EMA Fast crossed below Slow")

// ─── INFO TABLE ──────────────────────────────────────────

if show_table and barstate.islast
    var table t = table.new(position.top_right, 3, 8,
         bgcolor=color.new(color.black, 20),
         border_color=color.new(color.gray, 50),
         border_width=1)

    // Header
    table.cell(t, 0, 0, "ADX PRO [TCO]", bgcolor=color.new(color.navy, 10), text_color=color.white, text_size=size.small)
    table.cell(t, 1, 0, "VALUE",         bgcolor=color.new(color.navy, 10), text_color=color.white, text_size=size.small)
    table.cell(t, 2, 0, "STATUS",        bgcolor=color.new(color.navy, 10), text_color=color.white, text_size=size.small)

    // Candle
    candle_col = close > open ? color.new(color.green, 30) : color.new(color.red, 30)
    candle_txt = close > open ? "Bullish 🟢" : "Bearish 🔴"
    table.cell(t, 0, 1, "Candle",    bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 1, candle_txt,  bgcolor=candle_col,                text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 1, str.tostring(math.round(close, 2)), bgcolor=candle_col, text_color=color.white, text_size=size.tiny)

    // ADX Value
    table.cell(t, 0, 2, "ADX",                               bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 2, str.tostring(math.round(adx, 1)),    bgcolor=strength_col,               text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 2, strength_txt,                         bgcolor=strength_col,               text_color=color.white, text_size=size.tiny)

    // DI Direction
    adxdir_col = bull_bias ? color.new(color.green, 30) : color.new(color.red, 30)
    adxdir_txt = bull_bias ? "DI+ ▲ Bull" : "DI- ▼ Bear"
    bars_since = ta.barssince(ta.cross(di_plus, di_minus))
    table.cell(t, 0, 3, "Direction",  bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 3, adxdir_txt,   bgcolor=adxdir_col,                text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 3, str.tostring(bars_since) + " bars ago", bgcolor=adxdir_col, text_color=color.white, text_size=size.tiny)

    // DI Values
    table.cell(t, 0, 4, "DI+ / DI-",                                                   bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 4, str.tostring(math.round(di_plus,  1)),                          bgcolor=color.new(color.green, 40), text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 4, str.tostring(math.round(di_minus, 1)),                          bgcolor=color.new(color.red,   40), text_color=color.white, text_size=size.tiny)

    // EMA Trend
    ema_col = ema_bull ? color.new(color.green, 30) : color.new(color.red, 30)
    ema_txt = ema_bull ? "Bullish 📈" : "Bearish 📉"
    table.cell(t, 0, 5, "EMA Trend", bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 5, ema_txt,     bgcolor=ema_col,                   text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 5, str.tostring(ema_fast_len) + "/" + str.tostring(ema_slow_len), bgcolor=ema_col, text_color=color.white, text_size=size.tiny)

    // Market Mode
    mode_txt = is_ranging ? "RANGING ↔" : bull_bias ? "TRENDING ▲" : "TRENDING ▼"
    mode_col = is_ranging ? color.new(color.orange, 30) : bull_bias ? color.new(color.green, 30) : color.new(color.red, 30)
    table.cell(t, 0, 6, "Market",  bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 6, mode_txt,  bgcolor=mode_col,                  text_color=color.white, text_size=size.small)
    table.cell(t, 2, 6, is_ranging ? "No Trade ⛔" : "Trade OK ✅", bgcolor=mode_col, text_color=color.white, text_size=size.tiny)

    // Divergence
    div_txt = bull_div ? "Bull DIV ⚠" : bear_div ? "Bear DIV ⚠" : "None ✅"
    div_col = (bull_div or bear_div) ? color.new(color.orange, 20) : color.new(color.gray, 55)
    table.cell(t, 0, 7, "Divergence", bgcolor=color.new(color.gray, 60), text_color=txtcol,      text_size=size.tiny)
    table.cell(t, 1, 7, div_txt,      bgcolor=div_col,                   text_color=color.white, text_size=size.tiny)
    table.cell(t, 2, 7, (bull_div or bear_div) ? "Caution!" : "Clean",  bgcolor=div_col, text_color=color.white, text_size=size.tiny)

Overview

ADX Trend Filter Pro plots ADX with DI plus and DI minus, classifies trend strength as weak, moderate, strong or very strong from adjustable thresholds, and overlays a fast and slow EMA band. Optional buy and sell markers can be limited to stronger trends, a divergence warning compares price swings with ADX, and an information table summarises the readings. Alerts and bar colouring are included. ADX measures trend strength rather than direction.

Details

Published by

rehanqx on GitHub

Code credit

RehanFX_Alpha | MUHAMMAD REHAN AFZAL, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum, Divergence

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
ADX Lengthint14adx_len
ADX Smoothingint14adx_smooth
Weak Thresholdint20adx_weak
Moderate Thresholdint30adx_mod
Strong Thresholdint40adx_strong
Fast EMAint12ema_fast_len
Slow EMAint50ema_slow_len
Only Strong Trend Signals (ADX > Moderate)boolfalseonly_strong
Show Divergence Warningbooltrueshow_div
Text Colorcolorcolor.graytxtcol
Show Info Tablebooltrueshow_table
Show Buy/Sell Signalsbooltrueshow_signals
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

The indicator scores whether a counter-move against the dominant structure is maturing and whether price has started turning back. It plots a composite score in a separate pane from weighted context, correction maturity, and exhaustion, scaled by trigger and a

Indicator v6 TrendOscillators & momentum
Updated 2 days ago · MIT GitHub repository of Directional Probability Engine v2 [WavesUnchained]

MTF MA bands + RSI

by InNoobWeTrust
4 stars

This indicator plots multi-timeframe moving average bands alongside a Relative Strength Index in a separate pane. It calculates up to four configurable moving averages across different timeframes, offering selectable types such as SMA, EMA, and WMA with colore

Indicator v6 Oscillators & momentumMoving averages
Updated yesterday · None stated GitHub repository of MTF MA bands + RSI
2 stars

This indicator plots the Vortex Indicator and the Relative Strength Index together in a separate pane. It calculates VI+ and VI- from absolute high-low ranges over a shared length, then draws RSI from a chosen source with a selectable SMA or EMA of the RSI. Ho

Indicator v5 Oscillators & momentumTrend
Updated 2 years ago · MIT GitHub repository of Combined Indicator RSI, Vortex

QQE + AK Trend + EFI

by realanthonyc
2 stars

This indicator computes and plots a QQE histogram using RSI of the chosen source smoothed with Wilder's ATR method, alongside an AK Trend line derived from fast EMAs with dynamic scale factors adjusted by timeframe. It also calculates Elder Force Index with ad

Indicator v6 TrendOscillators & momentum
Updated 10 months ago · MPL-2.0 GitHub repository of QQE + AK Trend + EFI

Kernal Cipher 2

by kdricha0602
1 stars

Kernal Cipher 2 is a lower-pane signal panel. It scores trend with fast, slow, and long EMAs, slope, Supertrend, and ADX, then blends WaveTrend, StochRSI, pivot divergence, volume, relative strength versus equity benchmarks, and beta. Green and red diamonds ma

Indicator v6 TrendOscillators & momentum
Updated 5 weeks ago · MIT GitHub repository of Kernal Cipher 2
1 stars

This indicator calculates a multi-factor trend and momentum score by combining triple exponential moving averages, Supertrend, ADX regime filters, WaveTrend, and StochRSI oscillators. It identifies regular divergences across pivot points, checks multi-timefram

Indicator v6 TrendOscillators & momentum
Updated 5 weeks ago · MIT GitHub repository of Momentum Confluence Suite [MCS] v2

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