All indicators
Trend / Price pane

Double Exponential Moving Average

Patrick Mulloy's double exponential moving average: an EMA with most of its lag removed, drawn on the candles.

  • DEMA
  • Built into Spectral
  • Updates every tick
  • dema
  • double ema
  • moving average
  • low lag
  • trend

By Spectral · v1.0.0

MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.

Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Double Exponential Moving Average on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

The Double Exponential Moving Average, published by Patrick Mulloy in 1994, is not an EMA applied twice but a lag correction: it takes an EMA of price, then an EMA of that EMA, and plots twice the first minus the second.

The second average measures how far the first one trails price, and subtracting it moves the line back toward price. On a steady trend the DEMA follows price with almost no delay, while still being smoother than price itself.

How to read it

Read it like a fast EMA: its slope gives the short-term direction, and price holding above a rising DEMA (or below a falling one) describes a move with follow-through. Because it reacts sooner, a DEMA crossing a slower average gives earlier signals than an EMA cross of the same lengths.

The lag correction also means it overshoots after sharp reversals and turns more often in choppy, sideways markets. Confirm turns with price structure.

Settings and limitations

Length defaults to 9 bars, as on TradingView; the presets add 21, 50 and 200. Both inner averages use the same length.

Like the EMA, the line starts at the first bar with no warm-up, so its earliest values lean on the first prices and settle after a few multiples of Length.

Notes

Computes 2 x EMA - EMA of EMA, Mulloy's formula. The EMAs start from the first value, like Spectral's EMA; platforms that start an EMA from a simple average, TradingView among them, draw nothing for the first 2 x Length - 2 bars, and the values agree once warmed up. The Triple EMA (TEMA) carries the same idea one step further.

Settings

Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.

SettingTypeDefaultRange or optionsWhat it does
LengthWhole number91 – 1000Length of both exponential averages inside the DEMA. Longer lengths are smoother and react later.
SourcePrice sourcecloseopen, high, low, close, hlc3Price the average is calculated from.

Presets

Each preset is its own entry in the Indicators toolbox, with these settings changed.

Toolbox entryShort nameSettings
DEMA 21DEMA 21Length: 21
DEMA 50DEMA 50Length: 50
DEMA 200DEMA 200Length: 200

What it draws

Lines

  • DEMAsolid · 1 px · primary#D49A7A

Source

Save it as dema.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.

// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
  schemaVersion: 2,
  id: 'dema',
  name: 'Double Exponential Moving Average',
  shortName: 'DEMA',
  version: '1.0.0',
  author: 'Spectral',
  description: 'Patrick Mulloy\'s double exponential moving average: an EMA with most of its lag removed, drawn on the candles.',
  pane: 'price',
  live: { lookback: 0 },
  inputs: {
    length: { type: 'integer', label: 'Length', default: 9, min: 1, max: 1000, description: 'Length of both exponential averages inside the DEMA. Longer lengths are smoother and react later.' },
    source: { type: 'source', label: 'Source', default: 'close', description: 'Price the average is calculated from.' },
  },
  plots: {
    dema: { label: 'DEMA', color: '#D49A7A', lineWidth: 1, primary: true },
  },
  presets: [
    { id: 'dema-21', name: 'DEMA 21', shortName: 'DEMA 21', inputs: { length: 21 } },
    { id: 'dema-50', name: 'DEMA 50', shortName: 'DEMA 50', inputs: { length: 50 } },
    { id: 'dema-200', name: 'DEMA 200', shortName: 'DEMA 200', inputs: { length: 200 } },
  ],
  docs: {
    overview: 'The Double Exponential Moving Average, published by Patrick Mulloy in 1994, is not an EMA applied twice but a lag correction: it takes an EMA of price, then an EMA of that EMA, and plots twice the first minus the second.\n\nThe second average measures how far the first one trails price, and subtracting it moves the line back toward price. On a steady trend the DEMA follows price with almost no delay, while still being smoother than price itself.',
    howToRead: 'Read it like a fast EMA: its slope gives the short-term direction, and price holding above a rising DEMA (or below a falling one) describes a move with follow-through. Because it reacts sooner, a DEMA crossing a slower average gives earlier signals than an EMA cross of the same lengths.\n\nThe lag correction also means it overshoots after sharp reversals and turns more often in choppy, sideways markets. Confirm turns with price structure.',
    settings: 'Length defaults to 9 bars, as on TradingView; the presets add 21, 50 and 200. Both inner averages use the same length.\n\nLike the EMA, the line starts at the first bar with no warm-up, so its earliest values lean on the first prices and settle after a few multiples of Length.',
    notes: 'Computes 2 x EMA - EMA of EMA, Mulloy\'s formula. The EMAs start from the first value, like Spectral\'s EMA; platforms that start an EMA from a simple average, TradingView among them, draw nothing for the first 2 x Length - 2 bars, and the values agree once warmed up. The Triple EMA (TEMA) carries the same idea one step further.',
  },
  calculate(ctx) {
    const { bars, inputs, ta } = ctx;
    const ema1 = ta.ema(ta.source(bars, inputs.source), inputs.length);
    const ema2 = ta.ema(ema1, inputs.length);
    return { plots: { dema: ema1.map((value, index) => (value === null || ema2[index] === null ? null : 2 * value - ema2[index])) } };
  },
};

Adapt it with an LLM

Paste this into your assistant and replace the second-to-last line with the change you want.

Start from this Spectral custom indicator: https://spectral.trade/indicators/dema.js
Format reference: https://spectral.trade/docs/custom-indicators.llm.md
Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match.
Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow.
Change I want: <describe the change>
Answer with the complete file in one code block, ready to save as <id>.js.