Adaptive / TrendPine Script v6

Ehlers Dynamic Smoothed Moving Average Pine Script — Complete TradingView Guide

The Ehlers Dynamic Smoothed Moving Average (EDSMA) is an adaptive moving average indicator in Pine Script that automatically adjusts its smoothing speed based on current market momentum. Unlike a fixed EMA, the EDSMA uses a 2-Pole Super Smoother Filter to measure price change velocity, then scales it by standard deviation to compute a dynamic alpha coefficient. When the market is trending strongly, the EDSMA tracks price closely and reacts quickly. When the market is ranging or choppy, the alpha drops near zero and the line barely moves — filtering out noise automatically. This self-adjusting behavior makes the EDSMA one of the most versatile trend tools available in Pine Script v6, suitable for stocks, crypto, forex, and futures across 1H to Daily timeframes. This guide covers the complete implementation, all parameters, three concrete trading strategies, and how to generate EDSMA Pine Script instantly with Pineify.

What Is the Ehlers Dynamic Smoothed Moving Average?

The Ehlers Dynamic Smoothed Moving Average (EDSMA) is an adaptive trend indicator that dynamically adjusts its smoothing coefficient based on a scaled momentum signal, used to filter market noise while staying responsive during strong trends. Developed by John F. Ehlers, an electrical engineer who pioneered digital signal processing (DSP) techniques in financial markets, the EDSMA was introduced as part of his cybernetic analysis framework, building on the Super Smoother Filter concepts he formalized in his 2013 book "Cycle Analytics for Traders."

The EDSMA algorithm operates in three stages. First, it computes a zero-lag difference signal: zeros = source - source[2], then averages consecutive zero values (avgZeros = (zeros + zeros[1]) / 2). Second, it passes this averaged difference through a 2-Pole Super Smoother Filter (SSF) with a fixed period of 20, which removes high-frequency noise while preserving trend direction. Third, the SSF output is rescaled by its own standard deviation over the user-defined length window: scaledFilter = ssf / stdev(ssf, length). This scaling normalizes the filter output so that scaledFilter expresses momentum in units of standard deviations, not raw price points.

The dynamic alpha is then: alpha = 5 × |scaledFilter| / length. When price is moving strongly in one direction, the scaled filter is large, alpha rises toward 1, and the EDSMA behaves almost like a real-time tracker. When the market is flat, the scaled filter approaches 0, alpha approaches 0, and the EDSMA line barely moves — effectively pausing until directional momentum resumes. The final EDSMA value is computed as a standard EMA-style recursion: edsma = alpha × source + (1 − alpha) × edsma[1].

The EDSMA is applicable to all liquid asset classes: equities, cryptocurrency, forex pairs, and futures contracts. It performs best on 1H, 4H, and Daily timeframes where trends persist long enough for the adaptive filter to provide an advantage over a fixed EMA. On 1-minute charts, random noise can create erratic alpha spikes; on weekly charts, the signal is smooth but very slow to act on.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

1H, 4H, Daily

Overlay

Yes — plots directly on price chart

EDSMA Pine Script Code Example

The complete Pine Script v6 code below implements the full EDSMA algorithm — including the internal 2-Pole Super Smoother helper — and plots the result as a blue line directly on the TradingView price chart. To use it, open the TradingView Pine Script editor (Alt+P), paste the code, and click Add to chart. The indicator applies to the close series with a default length of 14.

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="Ehlers Dynamic Smoothed Moving Average", overlay=true, max_labels_count=500)

// 2-Pole Super Smoother Filter (internal helper)
p_ta_get2PoleSSF(series float src, simple int length) =>
    PI = 2 * math.asin(1)
    arg = math.sqrt(2) * PI / length
    a1 = math.exp(-arg)
    b1 = 2 * a1 * math.cos(arg)
    c2 = b1
    c3 = -math.pow(a1, 2)
    c1 = 1 - c2 - c3
    ssf = 0.0
    ssf := c1 * src + c2 * nz(ssf[1]) + c3 * nz(ssf[2])
    ssf

// EDSMA core function
p_ta_edsma(series float source, simple int length) =>
    float result = 0.0
    zeros = source - nz(source[2])
    avgZeros = (zeros + zeros[1]) / 2
    ssf = p_ta_get2PoleSSF(avgZeros, 20)
    stdev = ta.stdev(ssf, length)
    scaledFilter = stdev != 0 ? ssf / stdev : 0
    alpha = 5 * math.abs(scaledFilter) / length
    edsma = 0.0
    edsma := alpha * source + (1 - alpha) * nz(edsma[1])
    result := edsma
    result

// Plot EDSMA with length=14 applied to close
p_ind_1 = p_ta_edsma(close, 14)
plot(p_ind_1, "EDSMA", color.rgb(41, 98, 255, 0), 1)

Chart Preview

Ehlers Dynamic Smoothed Moving Average (EDSMA) indicator Pine Script code example in TradingView

EDSMA Parameters

ParameterDefault ValueDescriptionRecommended Range
sourcecloseThe price series to smooth. Any numeric series: close, hlc3, or a custom calculated series.Any numeric series
length14Lookback window for the standard deviation normalization and the alpha divisor. Larger values produce a slower, more stable adaptive response; smaller values make alpha more sensitive to short-term momentum.5–100 depending on style
SSF period20 (fixed)Internal 2-Pole Super Smoother Filter period applied to the averaged zero-lag difference signal. Fixed at 20 in this implementation per Ehlers' original design.Fixed — not user-configurable

Tuning Guide by Trading Style

  • Scalping (1m–15m charts): length 5–10 — alpha responds quickly to momentum bursts; use with tight stops
  • Day trading (1H–4H charts): length 14–20 — the default 14 balances responsiveness and noise suppression
  • Swing trading (4H–Daily charts): length 20–50 — smooth enough to hold positions through minor retracements
  • Position trading (Daily–Weekly charts): length 50–100 — very stable line that only reacts to large-scale directional momentum

Trading Strategies Using the EDSMA Indicator

The EDSMA is most effective as a dynamic trend filter or adaptive crossover system. Its self-adjusting alpha means it naturally reduces whipsaws in low-momentum markets. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — EDSMA Slope Trend Filter + RSI Confirmation

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

Use the slope of the EDSMA as the primary trend filter and RSI(14) as a momentum gate. The adaptive alpha ensures the EDSMA rises only when real momentum exists, reducing the number of false trend calls compared to a fixed EMA slope filter.

  1. Compute EDSMA(14) on close and evaluate slope: trendUp = edsma > edsma[1]
  2. Add RSI(14) momentum filter: rsi = ta.rsi(close, 14)
  3. Long entry: trendUp is true AND rsi > 50 AND close > edsma
  4. Exit long: EDSMA slope turns negative (edsma < edsma[1]) for 2 consecutive bars
  5. Short entry (optional): trendUp is false AND rsi < 50 AND close < edsma
  6. Stop loss: 1.5× ATR(14) below entry for longs

Strategy 2 — Dual EDSMA Crossover System

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

A dual-length EDSMA crossover uses a fast EDSMA(8) and a slow EDSMA(21). Because both lines adapt to momentum, crossovers occur primarily during genuine trend shifts rather than choppy sideways movements.

  1. Plot fast EDSMA with length 8: edsmaFast = p_ta_edsma(close, 8)
  2. Plot slow EDSMA with length 21: edsmaSlow = p_ta_edsma(close, 21)
  3. Long entry: edsmaFast crosses above edsmaSlow (use ta.crossover(edsmaFast, edsmaSlow))
  4. Confirm with volume: volume > ta.sma(volume, 20) * 1.2
  5. Exit: edsmaFast crosses below edsmaSlow
  6. Risk per trade: maximum 2% of account equity

Strategy 3 — EDSMA Bounce in Pullback Entries

Market environment: established uptrend with pullbacks · Best timeframe: Daily

When the EDSMA is rising (trending), price often pulls back to touch or briefly dip below the EDSMA line before resuming the trend. This strategy uses the EDSMA as a dynamic support level for pullback entries, combined with a Bollinger Band squeeze filter.

  1. Confirm uptrend: EDSMA(20) has been rising for the past 5 bars (edsma > edsma[5])
  2. Wait for pullback: close drops to within 0.5% of EDSMA value
  3. Add Bollinger Band squeeze confirmation: bb_width = ta.bbw(close, 20, 2) — enter only when bb_width is below its 50-bar average (low volatility pullback)
  4. Entry trigger: close crosses back above EDSMA on the next bar
  5. Target: 2× the distance from entry to EDSMA (risk:reward ≥ 2:1)
  6. Stop loss: close below EDSMA by more than 1× ATR(14)

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 EDSMA Indicator in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account gives you instant access to the AI Coding Agent.

  2. 2

    Click "New Indicator"

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

  3. 3

    Describe the EDSMA indicator

    Type a prompt such as: "Generate an Ehlers Dynamic Smoothed Moving Average (EDSMA) with length 14 applied to close, plotted as a blue overlay line." Pineify's AI Coding Agent generates the complete Pine Script v6 code — including the 2-Pole Super Smoother Filter helper — in seconds.

  4. 4

    Copy the code 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 the EDSMA plotted on your chart.

  5. 5

    Adjust parameters for your strategy

    In the TradingView indicator settings panel, modify the length parameter to match your trading style — use 5–10 for scalping, 14–20 for day trading, or 20–50 for swing trading. No code editing required.

Frequently Asked Questions

Related Pine Script Indicators

Build Your EDSMA Indicator in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script v6 indicators — including the full Ehlers Dynamic Smoothed Moving Average with 2-Pole Super Smoother — instantly for free.

Try Pineify Free