Indicator · Pine Script v5 · On the chart

DEMA 200 and ADX Combined Indicator

by xunxuntj

A price-chart indicator that plots a 200-length double exponential moving average and colours it by trend strength.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code151
Settings9inputs
LicenceMIT
Last update3 days ago26 Oct 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

151 lines of Pine Script v5 from archive/obsolete_docs_and_reports/adx_dema_combined.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adx_dema_combined.pine
//@version=5
indicator("DEMA 200 & ADX Combined Indicator", shorttitle="DEMA+ADX HUD", overlay=true)

// ==========================================
// 1. INPUT PARAMETERS
// ==========================================

// DEMA Settings
gp_dema = "=== DEMA 200 Settings ==="
dema_len = input.int(200, minval=1, title="DEMA Length", group=gp_dema)
show_dema = input.bool(true, title="Show DEMA Line", group=gp_dema)

// ADX Settings
gp_adx = "=== ADX Settings ==="
adx_len = input.int(14, minval=1, title="ADX Length", group=gp_adx)
adx_threshold = input.int(20, minval=1, title="ADX Trend Strength Threshold", group=gp_adx, tooltip="Values above this threshold indicate a strong trend (typically 20 or 25).")
adx_tf = input.timeframe("30", "ADX Timeframe", options=["30", "60"], group=gp_adx, tooltip="Select ADX calculation timeframe: 30 (30 minutes), 60 (1 hour).")
color_bg_low_adx = input.bool(false, title="Highlight Low ADX Zones (Choppy Markets)", group=gp_adx, tooltip="Colors the background when ADX is below the threshold.")

// HUD Dashboard Settings
gp_hud = "=== HUD Dashboard Settings ==="
show_hud = input.bool(true, title="Show HUD Table", group=gp_hud)
hud_pos = input.string("top_right", title="HUD Position", options=["top_right", "top_left", "bottom_right", "bottom_left"], group=gp_hud)
hud_size = input.string("small", title="Text Size", options=["auto", "tiny", "small", "normal", "large"], group=gp_hud)

// ==========================================
// 2. INDICATOR CALCULATIONS
// ==========================================

// Double Exponential Moving Average (DEMA)
dema(src, length) =>
    ema1 = ta.ema(src, length)
    ema2 = ta.ema(ema1, length)
    2 * ema1 - ema2

dema_val = dema(close, dema_len)

// Helper function to calculate DMI/ADX
f_dmi(len) =>
    [p_di, m_di, adx] = ta.dmi(len, len)
    [p_di, m_di, adx]

// Calculate ADX & Directional Movement on the requested timeframe
[plus_di, minus_di, adx_val] = request.security(syminfo.tickerid, adx_tf, f_dmi(adx_len), barmerge.gaps_off, barmerge.lookahead_off)

// Trend strength & direction conditions
is_trending = adx_val >= adx_threshold
is_bullish = plus_di > minus_di
is_bearish = minus_di > plus_di

// ==========================================
// 3. CHART PLOTS
// ==========================================

// Color DEMA line dynamically based on trend strength and direction:
// - Green: Bullish Trend (Price > DEMA and ADX >= Threshold)
// - Red: Bearish Trend (Price < DEMA and ADX >= Threshold)
// - Gray: Choppy / Weak Trend (ADX < Threshold)
dema_color = not is_trending ? color.gray : 
             (close > dema_val ? color.green : color.red)

plot(show_dema ? dema_val : na, title="DEMA 200", color=dema_color, linewidth=2)

// Color background when the market is choppy (Low ADX)
bgcolor(color_bg_low_adx and not is_trending ? color.new(color.orange, 95) : na, title="Low ADX Choppy Zone")

// ==========================================
// 4. HUD DASHBOARD TABLE
// ==========================================

// Convert position string input to Pine Script position type
getTablePosition(pos) =>
    switch pos
        "top_left"     => position.top_left
        "bottom_left"  => position.bottom_left
        "bottom_right" => position.bottom_right
        => position.top_right

// Convert text size string input to Pine Script size type
getTableTextSize(sz) =>
    switch sz
        "auto"   => size.auto
        "tiny"   => size.tiny
        "normal" => size.normal
        "large"  => size.large
        => size.small

var table hud = na
if show_hud
    hud := table.new(getTablePosition(hud_pos), 2, 5, bgcolor=color.new(color.black, 20), border_color=color.gray, border_width=1)

if show_hud and barstate.islast
    t_sz = getTableTextSize(hud_size)
    
    // Header
    table.cell(hud, 0, 0, "Indicator", text_color=color.white, bgcolor=color.blue, text_size=t_sz)
    table.cell(hud, 1, 0, "Status / Value", text_color=color.white, bgcolor=color.blue, text_size=t_sz)
    
    // Row 1: ADX (Trend Strength)
    adx_status_text = is_trending ? "Trending (" + str.tostring(adx_val, "#.#") + ")" : "Choppy (" + str.tostring(adx_val, "#.#") + ")"
    adx_status_color = is_trending ? color.green : color.orange
    tf_suffix = adx_tf == "60" ? "1H" : adx_tf == "30" ? "30m" : adx_tf
    table.cell(hud, 0, 1, "ADX (" + str.tostring(adx_len) + ") [" + tf_suffix + "]", text_color=color.white, text_size=t_sz)
    table.cell(hud, 1, 1, adx_status_text, text_color=adx_status_color, text_size=t_sz)
    
    // Row 2: DMI (+DI vs -DI)
    dmi_status_text = is_bullish ? "+DI > -DI (Bullish)" : "-DI > +DI (Bearish)"
    dmi_status_color = is_bullish ? color.green : color.red
    table.cell(hud, 0, 2, "+DI / -DI", text_color=color.white, text_size=t_sz)
    table.cell(hud, 1, 2, str.tostring(plus_di, "#.#") + " / " + str.tostring(minus_di, "#.#") + " (" + (is_bullish ? "Bull" : "Bear") + ")", text_color=dmi_status_color, text_size=t_sz)
    
    // Row 3: DEMA 200 Relation
    dema_status_text = close > dema_val ? "Price > DEMA (Bullish)" : "Price < DEMA (Bearish)"
    dema_status_color = close > dema_val ? color.green : color.red
    table.cell(hud, 0, 3, "DEMA " + str.tostring(dema_len), text_color=color.white, text_size=t_sz)
    table.cell(hud, 1, 3, dema_status_text, text_color=dema_status_color, text_size=t_sz)

    // Row 4: Combined Signal
    combined_signal = ""
    combined_color = color.white
    if is_trending
        if close > dema_val and is_bullish
            combined_signal := "Strong LONG Signal"
            combined_color := color.green
        else if close < dema_val and is_bearish
            combined_signal := "Strong SHORT Signal"
            combined_color := color.red
        else
            combined_signal := "Mixed Trend"
            combined_color := color.yellow
    else
        combined_signal := "No Trend (Avoid Trading)"
        combined_color := color.gray
        
    table.cell(hud, 0, 4, "Action Signal", text_color=color.white, text_size=t_sz)
    table.cell(hud, 1, 4, combined_signal, text_color=combined_color, text_size=t_sz)

// ==========================================
// 5. ALERT CONDITIONS
// ==========================================

alertcondition(ta.crossover(close, dema_val), title="Price Crossed Above DEMA", message="Price crossed above DEMA {{interval}}")
alertcondition(ta.crossunder(close, dema_val), title="Price Crossed Below DEMA", message="Price crossed below DEMA {{interval}}")
alertcondition(ta.crossover(adx_val, adx_threshold), title="ADX Crossed Above Threshold (Trend Starts)", message="ADX crossed above threshold ({{value}})")
alertcondition(ta.crossunder(adx_val, adx_threshold), title="ADX Crossed Below Threshold (Trend Ends)", message="ADX crossed below threshold ({{value}})")

// Combined Alert signals
long_alert = is_trending and ta.crossover(close, dema_val) and is_bullish
short_alert = is_trending and ta.crossunder(close, dema_val) and is_bearish
alertcondition(long_alert, title="Combined Buy/Long Signal", message="Combined Long Signal on {{ticker}} at {{close}}")
alertcondition(short_alert, title="Combined Sell/Short Signal", message="Combined Short Signal on {{ticker}} at {{close}}")

Overview

The line turns green when price is above it and ADX is at or above a threshold, red when price is below it, and grey when ADX is weak. ADX and directional movement are read from a 30 or 60 minute timeframe. Optional shading marks low-ADX choppy zones, and a configurable table shows the readings.

Details

Published by

xunxuntj on GitHub

Draws

On the price chart

Markets

Crypto

Timeframes

M15-H1

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
DEMA Lengthint200dema_len
Show DEMA Linebooltrueshow_dema
ADX Lengthint14adx_len
ADX Trend Strength Thresholdint20adx_threshold
ADX Timeframetimeframe30adx_tf
Highlight Low ADX Zones (Choppy Markets)boolfalsecolor_bg_low_adx
Show HUD Tablebooltrueshow_hud
HUD Positionstringtop_righthud_pos
Text Sizestringsmallhud_size
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

228 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist
92 stars

This indicator plots five moving averages of a chosen source on the price chart, defaulting to EMA lengths 10, 20, 30, 40 and 50. The user can switch the average type to SMA, WMA or HMA and recolor each line. Wide translucent glows sit under the lines, and sof

Indicator v5 TrendMoving averages
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Rainbow MA Ribbon 10-50

EMA Ribbon Overlay

by iamrichardD
57 stars

Calculates exponential moving averages for fast, pivot, and slow lengths along with optional 50, 100, and 200 simple moving average context lines. It visualizes bullish and bearish ribbon fills on the main price chart alongside MACD calculations to generate ea

Indicator v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon Overlay
53 stars

This indicator analyzes historical candle direction and price range over a configurable lookback window to gauge market trend. It categorizes trend direction using candle count, price range sum, or both. Signals are filtered using a Simple Moving Average to en

Indicator v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of Candle Counter + MA + RSI + Mode
43 stars

This indicator evaluates market momentum and risk by calculating trend metrics and volatility stats, displaying them in an on-chart table pane. It measures short-term and long-term trend strength via two MACD configurations built on three customizable EMA leng

Indicator v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of Trend Strength & Volatility

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers