Deviation-Scaled Moving Average on TradingView
Ehlers DSMA adjusts an EMA-style weight using a filtered price change divided by its recent scale. Its response depends on that ratio, so a more volatile market does not automatically produce a faster line. This guide separates the original RMS approach from the standard-deviation EDSMA variant and gives you a Pine example with explicit startup and closing-bar rules.
alpha = 5 × |filtered / scale| / period
DSMA = previous DSMA + alpha × (source − previous DSMA)
When alpha is 0.25, the line closes one quarter of the current gap. An uncapped alpha above 1 can overshoot the source.
Specify which DSMA you mean
The July 2018 Traders' Tips implementation attributed to John Ehlers uses a two-pole Super Smoother with period N/2 and an RMS denominator. The public TradingView script by everget also uses the DSMA name; its release notes mention a choice of filter poles. Names alone are insufficient for numerical comparison. Sources: published implementation and TradingView author page.
| Choice | Published RMS DSMA | Current Pineify EDSMA helper |
|---|---|---|
| Price input | Source minus source two bars ago | Same difference, with a zero fallback for missing history |
| Super Smoother | Two poles; filter period N/2 | Two poles; fixed filter period 20 |
| Scale | RMS: square root of mean squared filter values | Population standard deviation of filter values |
| Alpha | 5 × absolute normalized filter / N | Same ratio form, different denominator |
| Startup | Platform history and seed matter | Prior DSMA uses a zero fallback |
RMS measures distance from zero; standard deviation measures distance from the window mean. For a hypothetical filter window [2, 2, 2, 2], RMS is 2 and standard deviation is 0. Thus the RMS normalized value is 1, while the zero-denominator fallback in the current EDSMA helper gives 0. A nominally zero-mean filter need not have a zero mean in every finite window.
The example below implements the RMS choice with its own stated initialization. It is an educational reference, not a replacement for Pineify's built-in helper or a promise to match every community script. At N = 40 the two filter periods coincide, but the denominators and startup rules still differ.
How changing volatility changes the response
These are independent hypothetical single-bar calculations, not a backtest. Hold N = 40, previous DSMA = 100, and source = 110. Prices and filter values use the same arbitrary price units. Each result is 100 + alpha × 10; the normalized ratio and alpha are unitless.
| Scenario | |Filter| | RMS | Ratio | Alpha | New DSMA |
|---|---|---|---|---|---|
| Small normalized move | 2 | 4 | 0.5 | 0.0625 | 100.625 |
| Larger current move | 8 | 4 | 2 | 0.25 | 102.500 |
| Both values double | 4 | 8 | 0.5 | 0.0625 | 100.625 |
| Scale rises alone | 2 | 8 | 0.25 | 0.03125 | 100.3125 |
A scale increase can reduce the response, while an unusually large current filtered value can increase it. Repeated noise can still move the line and create crossovers. The filter and the final smoothing both retain history; adaptation does not remove lag or establish a profitable entry rule.
For the RMS variant with the current value inside an N-value window, |filter/RMS| cannot exceed √N. Hence raw alpha cannot exceed 5/√N. At N = 40 the bound is about 0.7906; at N = 4 it is 2.5. Short periods can therefore overshoot. A standard-deviation denominator has no equivalent bound when the window mean is nonzero. Enabling an alpha cap changes the algorithm and must be part of the version you record.
Pine Script v6 with explicit initialization
The two-pole recursion filters the average of the current and previous two-bar price differences. The code uses exact π and √2 rather than the rounded constants in the published listing. RMS is the square root of the N-bar mean of squared filter values. Copy this standalone indicator into TradingView's Pine Editor and add it to a chart.
//@version=6
indicator("DSMA: RMS reference with explicit warm-up", overlay=true)
// Formula reference: TASC Traders' Tips, July 2018, EhlersDSMA.
// This example uses exact mathematical constants and explicit startup rules.
source = input.source(close, "Source")
length = input.int(40, "RMS period", minval=2)
capAlpha = input.bool(false, "Cap alpha at 1 (modified response)")
angle = math.sqrt(2.0) * math.pi / (0.5 * length)
decay = math.exp(-angle)
c2 = 2.0 * decay * math.cos(angle)
c3 = -decay * decay
c1 = 1.0 - c2 - c3
difference = bar_index >= 2 ? source - source[2] : 0.0
var float filtered = 0.0
filtered := c1 * (difference + nz(difference[1])) / 2.0 + c2 * nz(filtered[1]) + c3 * nz(filtered[2])
rms = math.sqrt(ta.sma(filtered * filtered, length))
ready = bar_index >= length + 1 and not na(rms)
scaled = ready and rms > 0.0 ? filtered / rms : 0.0
rawAlpha = 5.0 * math.abs(scaled) / length
alpha = capAlpha ? math.min(rawAlpha, 1.0) : rawAlpha
var float dsma = na
dsma := ready ? alpha * source + (1.0 - alpha) * nz(dsma[1], source) : source
plot(ready ? dsma : na, "DSMA", color=color.blue, linewidth=2)
plot(ready ? alpha : na, "Alpha", display=display.data_window)
plot(ready ? rms : na, "Filter RMS", display=display.data_window)
crossUp = ta.crossover(source, dsma)
crossDown = ta.crossunder(source, dsma)
confirmed = ready and ready[1] and barstate.isconfirmed
alertcondition(confirmed and crossUp, "Source crosses above DSMA", "Source closed above DSMA")
alertcondition(confirmed and crossDown, "Source crosses below DSMA", "Source closed below DSMA")- The first two price differences and missing filter states are zero. DSMA follows the source internally during warm-up, rather than starting the average at price zero.
- The first visible value is at bar index N + 1, the N + 2nd loaded bar. This is a defined startup rule, not proof that the recursive filter has fully settled. Compare later bars and repeat with more history.
- After warm-up, an exactly zero RMS sets alpha to zero and holds the previous DSMA. Near-zero RMS must be judged together with the numerator; it does not by itself imply a small alpha.
- The Data Window exposes alpha and RMS. The optional cap is off by default. If you enable it, a raw alpha above 1 becomes 1 and moves DSMA directly to the source.
Both alert conditions require a confirmed chart bar and a valid previous DSMA bar. Create an alert from the desired condition after adding the indicator. TradingView stores an alert snapshot; recreate it after changing the script or its settings. See bar-state rules and alert behavior.
DSMA, KAMA, and VIDYA adapt to different inputs
DSMA scales a filtered price-change signal. KAMA uses an efficiency ratio: net price movement divided by the sum of absolute bar-to-bar moves, then a squared blend of fast and slow smoothing factors. The CMO-based VIDYA documented by MetaTrader weights an EMA factor by the absolute Chande Momentum Oscillator. Equal period labels do not make their response speeds equal.
Compare a line before testing a strategy
- Record the exact source, symbol, timeframe, session, adjustment settings, length, filter poles and period, denominator, seed, and cap.
- Compare closed-bar DSMA, filter scale, and alpha values after warm-up. Test a flat sequence, a step, a steady ramp, and alternating moves. A line starting near zero is a seed issue to investigate.
- Only then specify entries, exits, sizing, costs, and slippage for a strategy test. A crossover indicator alone cannot establish win rate or expected return.
Educational indicator analysis only, not investment advice. The examples are calculations, not evidence of trading performance.
Turn a verified DSMA specification into Pine
Pineify's Pine Script AI Coding Agent can generate and edit code from your description. Specify the RMS formula, seed, filter period, and alpha cap explicitly, then ask it to check syntax. Compare the resulting values in TradingView before adding alerts. Syntax validation does not establish formula equivalence or trading performance.
Build an RMS-based Ehlers DSMA with N = 40, a two-pole filter at N/2, and the startup rules in this example. Show alpha and RMS in the Data Window. Keep the alpha cap optional and off by default. Check syntax, then add closing-bar crossover conditions after numerical comparison.Explore Pine Script AI Coding Agent
Use public formulas or code you are entitled to modify. A named indicator request does not grant access to proprietary source.
DSMA questions
Sources and implementation reviewed October 17, 2026. Continue with the TradingView indicators hub or Zero Lag EMA guide.