- The Reverse EMA applies an 8-stage cascaded Z-transform inversion to a compensated EMA, progressively extracting and subtracting the accumulated la...
- **Similar:** [EMA](../../trends_IIR/ema/ema.md), [Zlema](../../trends_IIR/zlema/zlema.md) | **Complementary:** StdDev | **Trading note:** Reverse-engineers price from EMA; finds the price that would produce a given EMA value. Useful for target levels.
The Reverse EMA applies an 8-stage cascaded Z-transform inversion to a compensated EMA, progressively extracting and subtracting the accumulated lag component. Where standard EMA smoothing introduces phase delay proportional to the filter order, the reverse cascade reconstructs the lag error through successively doubled power coefficients of the decay factor, producing a signal with dramatically reduced latency. O(1) per bar, zero allocation, 8 FMA operations in the critical path.
## Historical Context
John Ehlers introduced the Reverse EMA concept in his 2017 work on signal processing for traders. The technique builds on the observation that an EMA's transfer function in the Z-domain has a known, invertible structure. Rather than attempting a single-stage inversion (which would amplify noise catastrophically), Ehlers cascaded 8 stages where each stage uses exponentially increasing powers of the decay factor: $cc^1, cc^2, cc^4, cc^8, cc^{16}, cc^{32}, cc^{64}, cc^{128}$.
This doubling sequence means the 8 stages collectively address lag components across 8 orders of magnitude, from the immediate decay factor through its 128th power. The approach is mathematically elegant: each stage removes progressively deeper lag without the numerical instability of direct polynomial inversion.
No other major library (TA-Lib, Skender, Tulip, Ooples) implements this indicator, making QuanTAlib's implementation a reference.
## Architecture and Physics
### 1. Forward EMA with Warmup Compensation
The base EMA uses the standard IIR form with bias compensation:
The batch path uses a simple loop over `CalculateCore`. Since the algorithm is inherently serial (each stage depends on the prior bar's state), SIMD parallelization is not applicable. However, the FMA chain provides excellent instruction-level pipelining on modern CPUs.
### Quality Metrics
| Metric | Score | Notes |
|--------|-------|-------|
| Lag Reduction | 9/10 | Near-zero lag via 8-stage inversion |
Self-consistency validation: Streaming, Batch (TSeries), and Span Batch modes produce identical results to machine precision ($< 10^{-12}$).
## Common Pitfalls
1.**Not an overlay.** ReverseEma output is oscillator-type (centered around a trend-dependent baseline), not a price overlay. Plot in a separate window.
2.**Noise amplification.** The 8-stage cascade effectively "un-smooths" the EMA. For noisy data, the output will be noisier than the input. Consider pre-filtering.
3.**Period sensitivity.** Very small periods ($\leq 3$) produce extreme lag removal and correspondingly extreme noise. Periods of 10-30 are typical.
4.**State depth.** The 8-deep state chain (16 previous-bar values + EMA state) means bar corrections (`isNew=false`) must restore all 20+ state variables. The `record struct State` pattern handles this correctly.
5.**Not a standalone signal.** Best used as a component in larger systems (e.g., as a leading indicator to anticipate EMA crossovers) rather than as a direct trading signal.
6.**Warm-up convergence.** The EMA warmup compensation ensures valid output from bar 1, but the 8 reverse stages need several periods to stabilize. Treat output during the warmup phase with caution.
7.**Floating-point drift.** Over very long streams (>10,000 bars), cumulative FMA operations may introduce subtle drift. The current implementation accepts this as the drift is well within double precision tolerance.
## References
- Ehlers, J. F. (2017). "Reverse EMA." Technical analysis signal processing concepts.
- Ehlers, J. F. (2004). *Cybernetic Analysis for Stocks and Futures*. Wiley.