MACD with divergence signals
May 3, 2020

The MACD with divergence signals indicator identifies potential trend continuation opportunities by detecting hidden divergences during MACD crossovers in alignment with a long-term trend filter.
Usage
This tool is designed to find high-probability entry points by combining momentum, trend, and divergence. A signal is generated when the following conditions are met:
- Bullish Signal (Green Background): A bullish MACD crossover occurs (histogram crosses above zero) while the price is above the Trend EMA, and a bullish hidden divergence is detected.
- Bearish Signal (Red Background): A bearish MACD crossover occurs (histogram crosses below zero) while the price is below the Trend EMA, and a bearish hidden divergence is detected.
Users can utilize these signals to identify moments where a trend might be resuming after a temporary retracement.
Details
The indicator calculates a standard MACD oscillator and its signal line. It also incorporates a Trend EMA (defaulting to 200 periods) to act as a directional filter, ensuring signals only appear in the direction of the prevailing trend.
The hidden divergence logic looks for instances where:
- In an uptrend: Price makes a higher low while the MACD makes a lower low.
- In a downtrend: Price makes a lower high while the MACD makes a higher high.
By requiring a crossover to occur simultaneously with these divergence conditions, the script filters out premature signals and focuses on active shifts in momentum.
Settings
MACD 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 (default is Close).
- Signal Smoothing: The period for the signal line.
- Simple MA (Oscillator): Toggle to use a Simple Moving Average instead of an EMA for the MACD lines.
- Simple MA (Signal Line): Toggle to use a Simple Moving Average for the signal line.
Trend Settings
- TREND EMA Length: The period for the trend-filtering EMA (commonly 200).
- EMA Source: The price data used for the trend EMA calculation.
FAQ
How do I access MACD with divergence signals?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
What is the difference between regular and hidden divergence?
Regular divergence typically indicates a potential trend reversal, while the hidden divergence used in this script suggests trend continuation.
Can I use this for scalping?
Yes, the indicator can be applied to any timeframe. However, the Trend EMA length should be adjusted to match the specific volatility and trend characteristics of the chosen timeframe.
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.