MACD Divergence
Reversal entries when MACD histogram diverges from price (swing-detection based).
What it is
MACD Divergence is a reversal strategy that detects when momentum (MACD histogram) is fading even as price continues to make new extremes. The classical setup: price makes a higher high, but MACD makes a lower high — momentum is exhausting.
This is one of the more nuanced strategies in the engine. Implementation correctness matters — naive divergence detectors leak look-ahead bias by referencing future bars to confirm a swing high or low.
How signals fire
Bearish divergence (short entry): the strategy detects a confirmed price swing high that exceeds a previous swing high, while the corresponding MACD histogram swing high is *lower* than the previous MACD swing high. The entry triggers on the bar after the second swing is confirmed.
Bullish divergence (long entry): symmetric — price makes a lower low, MACD makes a higher low.
Critical: swing detection uses a look-back window (default 5 bars), and entries are only taken at confirmedAt (when the swing is no longer ambiguous). This avoids look-ahead bias.
Defaults: MACD 12/26/9, swing lookback 5, divergence window 30 bars, hold 6 bars.
When it works
Late-cycle exhaustion phases when a market has been trending strongly and momentum starts to wane before price tops or bottoms. Daily charts on indices and BTC have multiple textbook divergence reversals each year.
Markets with clear cyclical behaviour where swings tend to revert rather than extend indefinitely.
When it fails
Strong, persistent trends where divergences appear repeatedly but price keeps extending. The famous "stairs up, elevator down" market pattern can produce many false bearish divergences before the actual top.
Sideways markets where every minor swing produces a "divergence" that isn't really one.
Low-volume / illiquid markets where the MACD histogram is too noisy to define real swings.
Built-in presets
- Baseline
Standard MACD 12/26/9, 5-bar swing detection, 30-bar divergence window.
- Long-cycle
Slower MACD (12/52/9) and wider 8-bar swing / 50-bar window — for higher timeframes.
- Short-cycle
Faster MACD (8/17/6) and tighter 3-bar swing / 20-bar window — for shorter swings.
Recommended indicator filters
- ADX ≤ 25 — divergences work best when trend strength is moderating, not exploding.
- Volume × 1.0 SMA — confirm the divergence with declining-volume swings (classic exhaustion pattern).
Common pitfalls
- Using a swing lookback that's too small — every minor wiggle becomes a 'swing'.
- Trading bearish divergences in raging bull markets — they can persist for many bars without resolving.
- Ignoring the divergence window parameter — too wide and you'll match swings that aren't really related.
- Cherry-picking historic charts where divergences worked — surviorship bias is rampant in divergence literature.
Related indicators
MACD
MACDCore indicator. Understanding histogram dynamics is essential to interpreting divergence quality.
Exponential Moving Average
EMAMACD line is the difference between two EMAs — knowing EMA behaviour explains MACD.
Swing Highs / Lows
SwingsThe pattern detection mechanism MACD divergence relies on. Understand the lookback trade-off.
Related strategies
Related reading
Five backtest mistakes that wipe out real money
Read →Divergence detection is one of the easiest places to introduce look-ahead bias — read mistake #1 before trusting any divergence backtest.
Walk-forward analysis: detecting overfit before it burns you
Read →Divergence parameters (swing lookback, window size) overfit easily — walk-forward is essential validation.
Try MACD Divergence in the backtester
Open the engine, pick MACD Divergence, choose a preset, and run it against synthetic or your own historical data. Tune parameters, add filters, and see how it behaves out-of-sample with walk-forward and Monte Carlo analysis.
Open the backtester →Educational note: This page explains how MACD Divergence fires and the market conditions it suits. It does not constitute investment advice. Backtested results are hypothetical simulations on past data; they cannot guarantee future outcomes. See the full disclaimer.
Last updated: 2026-05-08