MACD Divergence [Optimized]
May 2, 2019

The MACD Divergence [Optimized] indicator identifies potential market reversals by detecting discrepancies between price action and the Moving Average Convergence Divergence (MACD) oscillator.
Usage
The indicator is primarily used to spot potential trend exhaustion or upcoming reversals. When the closing price reaches a new high or low but the MACD fails to follow suit, a divergence is signaled.
- Reversal Trading: Divergences often offer a high risk-to-reward ratio, though they require careful entry confirmation.
- Trend Context: At the end of a long trend, a slow test of the extreme point accompanied by a divergence often marks the transition from a trend to a consolidation phase.
- False Breakouts: Sudden trend candles appearing near support or resistance during a ranging market that trigger a divergence are often indicators of false breakouts.
- Confluence: It is highly recommended to use this tool alongside other technical patterns like Double Tops, Head and Shoulders, or Pin Bars, as well as secondary oscillators like the Stochastic.
Details
The script calculates divergences based on a lookback window (defaulting to 90 bars). It compares the historical price extremes (highest high/lowest low) against the corresponding MACD peaks and troughs. The inclusion of a "Divergence Threshold" allows for fine-tuning the sensitivity of the detection, ensuring that only significant gaps between price and momentum are flagged.
Settings
MACD Settings
- Fast Length: The period for the shorter Exponential Moving Average (EMA).
- Slow Length: The period for the longer EMA.
- Signal Length: The period for the EMA of the MACD line (Signal Line).
Divergence Settings
- Divergence Lookback: The number of historical bars used to determine price and MACD extremes.
- Divergence Threshold: A multiplier that defines how significant the difference between price and MACD must be to trigger a signal.
Display Settings
- Show MACD Lines/Histogram: Toggles the visibility of the core MACD components.
- Show Crossovers: Displays markers for Golden and Death crosses.
- Show Divergence Labels: Toggles the "Bull Div" and "Bear Div" labels on the oscillator.
- Compact Mode: Adjusts line widths and label sizes for better visibility on mobile devices.
FAQ
How do I use MACD Divergence [Optimized] on lower timeframes?
While recommended for 15m, 30m, and 1h charts, it can be used on 5m charts. In such cases, it is advised to increase the "Divergence Lookback" setting to 150 or higher to filter out noise.
What do the colored circles on the MACD line represent?
The colored circles represent standard MACD crossovers: bullish "Golden Crosses" and bearish "Death Crosses."
How can I get access to this indicator?
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.