Divergence MACD
Feb 5, 2020

The Divergence MACD indicator automatically detects and labels regular and hidden divergences between price action and the MACD oscillator to help traders identify potential trend reversals or continuations.
Usage
The Divergence MACD can be used to spot discrepancies between price and momentum. When price makes a lower low but the MACD makes a higher low, a regular bullish divergence occurs, suggesting a potential upward reversal. Conversely, when price makes a higher high but the MACD makes a lower high, a regular bearish divergence is signaled.
The indicator uses specific labels to identify these occurrences:
- "D" Label: Represents a Regular Divergence (Bullish in green, Bearish in red).
- "H" Label: Represents a Hidden Divergence (Bullish in light green, Bearish in light red).
Traders can use these signals to confirm entries or exits, often looking for regular divergences to find trend Exhaustion and hidden divergences to find trend continuation.
Details
The script calculates the standard MACD using Fast, Slow, and Signal smoothing parameters. It then identifies pivot points (highs and lows) on both the price and the MACD line. Divergence is confirmed when the relationship between two consecutive price pivots differs from the relationship between the corresponding MACD pivots within a defined lookback range.
Settings
- MACD Source: Determines the price source used for MACD calculations (default is Close).
- Fast Length: The period for the shorter Exponential Moving Average.
- Slow Length: The period for the longer Exponential Moving Average.
- Signal Smoothing: The period for the EMA of the MACD line.
- Pivot Lookback Right: The number of bars to the right of a pivot to confirm its peak or trough.
- Pivot Lookback Left: The number of bars to the left required to identify a pivot.
- Max of Lookback Range: The maximum number of bars to look back for the previous pivot.
- Min of Lookback Range: The minimum number of bars required between pivots.
- Plot Bullish/Bearish/Hidden: Toggle switches to enable or disable the visualization of specific divergence types.
FAQ
How do I interpret the "D" and "H" labels?
"D" stands for Regular Divergence, which typically indicates a potential reversal of the current trend. "H" stands for Hidden Divergence, which often suggests the current trend is likely to continue.
Why are some signals offset from the current bar?
Divergence detection relies on pivot points. Because a pivot requires a certain number of bars to the right (Pivot Lookback Right) to be confirmed as a peak or trough, the labels are plotted with an offset once the pivot is mathematically confirmed.
How can I access Divergence MACD?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.