The Double Exponential Moving Average (DEMA) is a faster, more responsive version of the traditional EMA. It was designed to reduce the lag inherent in trend-following indicators. Despite its name, it is not simply a "double smoothing" (which would increase lag); rather, it uses a clever combination of a single EMA and a double EMA to subtract lag from the original signal.
Patrick Mulloy introduced DEMA in the January 1994 issue of *Technical Analysis of Stocks & Commodities* magazine. His goal was to create a moving average that could respond more quickly to market changes than the standard EMA, making it more suitable for the faster-paced trading environments that were emerging at the time.
Standard moving averages introduce lag. If you smooth a moving average again (EMA of EMA), you get a smoother line, but with *more* lag. Mulloy's insight was that the difference between the single EMA and the double EMA represents a measure of the "lag error." By adding this difference back to the single EMA, you can effectively cancel out much of the lag.
Our implementation uses a zero-lag initialization technique for the internal EMAs. Instead of waiting for the EMA to converge from 0 (which takes hundreds of bars), we use a "compensator" factor that scales the early values to be statistically valid immediately.
**Configuration note:** Because DEMA is faster than EMA, you may need to use a slightly longer period (e.g., 14 instead of 10) to get comparable smoothness with better responsiveness.
- **Price Crossover:** Price crossing DEMA is a very aggressive signal.
- **DEMA/EMA Crossover:** Using DEMA(20) crossing EMA(20) can signal a change in momentum strength.
### When It Works Best
- **Fast Trends:** DEMA shines in markets that move quickly and reverse sharply.
- **Scalping:** Its low lag makes it ideal for short-term trading on 1-minute or 5-minute charts.
### When It Struggles
- **Whipsaws:** Because it is so responsive, DEMA produces many false signals in choppy, sideways markets. It offers very little noise filtering compared to SMA or WMA.
## Comparison: DEMA vs EMA vs TEMA
| Aspect | EMA | DEMA | TEMA |
|--------|-----|------|------|
| **Lag** | Moderate | Low | Very Low |
| **Smoothness** | Moderate | Low | Very Low |
| **Responsiveness** | Moderate | High | Very High |
| **Overshoot** | Minimal | Moderate | High |
**Summary:** Use DEMA when EMA is too slow but you don't want the extreme volatility of TEMA (Triple EMA).
## Architecture Notes
This implementation makes specific trade-offs:
### Choice: Zero-Lag Initialization
- **Alternative:** Seed with first value or SMA.
- **Trade-off:** Slightly more complex math (`1/(1-decay)` scaling).
- **Rationale:** Provides valid values from the very first bar, eliminating the "warmup period" artifact common in other libraries.
### Choice: Double Precision State
- **Alternative:** Decimal.
- **Trade-off:** Precision vs Speed.
- **Rationale:** Double is significantly faster and provides sufficient precision for financial time series (15-17 digits).