MACD Divergences by @DaviddTech
Aug 25, 2021

The MACD Divergences indicator identifies regular and hidden divergences between price action and the Moving Average Convergence Divergence (MACD) oscillator to highlight potential trend reversals or continuations.
Usage
The Usage section focuses on identifying price-oscillator discrepancies to gauge market momentum. Users can apply this tool to spot two primary types of signals:
- Regular Divergences: These occur when price makes a new extreme (higher high or lower low) that is not confirmed by the MACD line, often signaling a potential trend reversal.
- Hidden Divergences: These occur when the MACD makes a new extreme while price does not, often suggesting a continuation of the prevailing trend.
The indicator plots labels and connecting lines directly on the oscillator pane. Labels are offset by the "Pivot Lookback Right" value to ensure the pivot point is confirmed before a signal is displayed.
Details
The script calculates the MACD line based on the difference between two moving averages (Fast and Slow) and a Signal line representing a smoothed average of the MACD. Divergence detection is based on pivot points found within a user-defined lookback window.
To ensure higher signal quality, the "Don't touch the zero line" setting filters regular bullish divergences to only appear when the MACD is below zero, and regular bearish divergences only when the MACD is above zero. This ensures that the momentum shift is occurring at an extreme rather than near the baseline.
Settings
- Fast Length: The period for the shorter-term moving average.
- Slow Length: The period for the longer-term moving average.
- Source: The price data used for MACD calculations (e.g., Close, Open, HL2).
- Signal Smoothing: The period for the Signal line moving average.
- Oscillator MA Type: Choose between SMA or EMA for the MACD line components.
- Signal Line MA Type: Choose between SMA or EMA for the Signal line smoothing.
- Don't touch the zero line?: When enabled, regular divergences are filtered based on their position relative to the zero level.
- Pivot Lookback Right/Left: The number of bars required to the right and left of a point to confirm it as a pivot high or low.
- Max/Min Lookback Range: Defines the window of bars searched to find a previous pivot for comparison.
- Plot Bullish/Bearish: Toggles the visibility of regular bullish and bearish divergence labels.
- Plot Hidden Bullish/Bearish: Toggles the visibility of hidden trend continuation signals.
FAQ
How do I interpret the "H Bull" and "H Bear" labels? These represent "Hidden" divergences. An "H Bull" suggests bullish trend continuation, while an "H Bear" suggests bearish trend continuation.
Why do labels appear several bars after a peak or trough? The script uses pivot lookbacks to confirm a high or low. The labels are plotted once the "Pivot Lookback Right" requirement is met, ensuring the point is a confirmed local extreme.
How can I get access to MACD Divergences? 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.