Trend Indicators

DEMA Indicator: Low-Lag Trend Signals vs EMA | AlfaTactix

📖 5 min read

📝 848 words

🏷️ Trend Indicators

In this page: what DEMA is, how it works, when to use it, a practical example with code, and a bonus tip.

Use DEMA in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.


DEMA on a price chart: illustration of the indicator and how it is used in technical analysis
DEMA – chart illustration

DEMA (Double Exponential Moving Average) Indicator Explanation

The Double Exponential Moving Average (DEMA) is a trend-following indicator developed by Patrick Mulloy that applies exponential smoothing twice to reduce lag while maintaining responsiveness. Unlike standard EMA which has inherent lag, DEMA uses a mathematical technique to eliminate most of the lag by applying EMA calculation twice with a correction factor. This results in an indicator that responds quickly to price changes while still providing trend smoothing, making it particularly useful for traders who want faster signals without excessive noise.

How DEMA Works: DEMA is calculated by first computing a standard EMA, then calculating an EMA of that EMA, and finally applying a correction: DEMA = 2 × EMA - EMA(EMA). This formula mathematically eliminates most of the lag inherent in moving averages by subtracting the lag component. The result is a moving average that responds approximately twice as fast as a standard EMA while maintaining smoothness. This makes DEMA ideal for identifying trend changes early and generating timely entry and exit signals.

When to Use DEMA:

  • Fast Trend Detection: DEMA helps identify trend changes faster than standard EMA, making it valuable for short to medium-term trading strategies that require quick response to market movements.
  • Reduced Lag Trading: DEMA's reduced lag makes it suitable for traders who want to enter trends early while still maintaining trend-following discipline and avoiding excessive whipsaws.
  • Dynamic Support/Resistance: DEMA can act as dynamic support in uptrends or resistance in downtrends, providing adaptive entry levels that respond quickly to price changes.

Advantages:

  • Significantly reduced lag compared to standard EMA, providing earlier trend reversal signals while maintaining smoothness and reducing noise compared to very short-period moving averages.
  • Maintains exponential weighting benefits (greater sensitivity to recent prices) while eliminating most of the inherent lag, offering optimal balance between responsiveness and reliability.
  • Works effectively across multiple timeframes and adapts well to different market conditions, from scalping to swing trading in stocks, forex, and cryptocurrencies.

Limitations:

  • DEMA can still generate false signals during choppy or ranging markets, requiring additional confirmation from other indicators or price action analysis to filter out noise.
  • The increased responsiveness may lead to more whipsaws compared to slower moving averages, especially in volatile markets, requiring proper risk management.
  • Like all trend-following indicators, DEMA performs best in trending markets and may struggle during extended consolidation periods.

In summary, DEMA is an advanced trend indicator that offers superior responsiveness through mathematical lag elimination. For comprehensive understanding, refer to Patrick Mulloy's original work on DEMA, Investopedia's technical analysis resources, and TradingView's DEMA documentation.

Practical Example: Using the DEMA Indicator in a Trading Strategy

The Double Exponential Moving Average (DEMA) is a trend-following indicator that reduces lag by applying exponential smoothing twice, making it more responsive than standard EMA. In a trading strategy, the DEMA indicator helps generate early entry and exit signals based on price crossovers and trend direction.

Scenario: You're creating a day trading strategy for Gold (XAU/USD) on a 15-minute chart. You want to buy when price crosses above DEMA(12) with bullish momentum and sell when price crosses below DEMA(12) with bearish momentum, capturing quick trend moves while minimizing lag.

Strategy Logic:

  • Calculate the DEMA(12) to identify the current trend direction with reduced lag.
  • Buy signal: When price crosses above DEMA(12) and DEMA(12) is above DEMA(26), indicating bullish trend initiation with confirmation.
  • Sell signal: When price crosses below DEMA(12) or DEMA(12) crosses below DEMA(26), indicating bearish trend reversal.

Backtrader Example:

import backtrader as bt

class DEMATrendStrategy(bt.Strategy):
    params = dict(
        dema_fast=12,
        dema_slow=26
    )
    
    def __init__(self):
        # Note: Backtrader may not have DEMA built-in, so we'll use EMA as approximation
        # DEMA = 2*EMA - EMA(EMA)
        self.ema_fast = bt.ind.EMA(period=self.p.dema_fast)
        self.ema_fast_smooth = bt.ind.EMA(self.ema_fast, period=self.p.dema_fast)
        self.dema_fast = 2 * self.ema_fast - self.ema_fast_smooth
        
        self.ema_slow = bt.ind.EMA(period=self.p.dema_slow)
        self.ema_slow_smooth = bt.ind.EMA(self.ema_slow, period=self.p.dema_slow)
        self.dema_slow = 2 * self.ema_slow - self.ema_slow_smooth
        
        self.price_above_dema = bt.ind.CrossOver(self.data.close, self.dema_fast)
        
    def next(self):
        if not self.position:
            # Buy when price crosses above fast DEMA and fast DEMA is above slow DEMA
            if (self.price_above_dema[0] > 0 and 
                self.dema_fast[0] > self.dema_slow[0]):
                self.buy()
        else:
            # Sell when price crosses below fast DEMA or fast DEMA crosses below slow DEMA
            if (self.price_above_dema[0] < 0 or 
                (self.dema_fast[0] < self.dema_slow[0] and self.dema_fast[-1] >= self.dema_slow[-1])):
                self.sell()

# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(DEMATrendStrategy)

Expected Outcome: By using the DEMA indicator, your strategy identifies trend changes earlier than standard EMA-based systems, helping you enter trends at their inception and exit before significant reversals. This approach leads to better entry timing, reduced lag in signal generation, and improved profit potential while maintaining trend-following characteristics.

💡 Bonus Tip

Consider using DEMA in combination with volume confirmation and ATR for stop-loss placement. When price crosses above DEMA with increasing volume, it suggests strong buying interest. Setting stop-loss at 1.5× ATR below DEMA can help protect profits while allowing for natural market fluctuations. This technique can significantly improve the reliability of DEMA-based trading strategies.

Using the DEMA indicator ensures your strategy captures trend changes early while maintaining trend-following discipline, improving entry and exit timing based on lag-reduced trend analysis.

Use DEMA in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.

Try Strategy Builder

Use this indicator in Strategy Builder — free

Create free account