MACD Divergences
Aug 23, 2022

The MACD Divergences indicator identifies and highlights both classic and hidden divergences between price action and the MACD histogram to detect potential trend reversals or continuations.
Usage
The Usage section describes how the script can be used to identify market shifts. This tool automatically plots labels and lines when a divergence is detected between the peaks/troughs of the price and the MACD histogram.
- Classic Bullish Divergence: Occurs when price makes a lower low but the MACD histogram makes a higher low. This suggests waning bearish momentum and a possible upward reversal.
- Classic Bearish Divergence: Occurs when price makes a higher high but the MACD histogram makes a lower high, indicating weakening bullish momentum.
- Hidden Divergences: These are often used as trend continuation signals. A hidden bullish divergence (higher low in price, lower low in MACD) suggests the uptrend is likely to continue.
Details
The script calculates the standard Moving Average Convergence Divergence (MACD) using three user-defined lengths (Fast, Slow, and Signal). It then scans the most recent and historical histogram cycles to find peaks and valleys. By comparing these oscillator points with the corresponding price highs and lows, the algorithm determines if a divergence exists. The script differentiates between "Classic" (solid lines) and "Hidden" (dashed lines) divergences for clearer chart interpretation.
Settings
General Settings
- Fast Length: The period for the shorter Exponential Moving Average (default: 12).
- Slow Length: The period for the longer Exponential Moving Average (default: 26).
- Source: The price data used for calculation (default: Close).
- Signal Smoothing: The period for the Signal line's Exponential Moving Average (default: 9).
Visual Settings
- Color Settings: Customize the colors for the MACD and Signal lines.
- Histogram: Adjust the colors for growing and falling histogram bars above and below the zero line.
FAQ
How do I interpret the dashed versus solid lines?
Solid lines represent classic divergences, which typically signal potential trend reversals. Dashed lines represent hidden divergences, which usually suggest the current trend is likely to continue.
Can I set up alerts for specific divergence types?
Yes, the indicator includes specific alert conditions for Classic Bullish, Hidden Bullish, Classic Bearish, and Hidden Bearish divergences, as well as a generic alert for any detected divergence.
How do I access this tool?
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.