Divergence Indicator
May 13, 2023

The Divergence Indicator tool is a multi-oscillator technical analysis script designed to identify potential bullish and bearish signals by detecting price divergences across the RSI, Stochastic, and MACD indicators simultaneously.
Usage
The Divergence Indicator is used to spot potential trend reversals or continuations by highlighting points where price action and momentum oscillators are no longer in sync.
- Bullish Signals: Represented by circles below the price bars. These occur when the price makes lower lows while momentum (RSI, Stochastic, and MACD) shows rising strength, or when a MACD crossover occurs near the zero line.
- Bearish Signals: Represented by circles above the price bars. These occur when the price makes higher highs while momentum indicators are falling, or when a MACD crossunder occurs near the zero line.
Traders often use these signals to identify exhaustion in the current trend. For higher conviction, users should look for signals where the fast EMA remains above the slow EMA for bullish setups, or below for bearish setups, to ensure the underlying trend supports the divergence.
Details
The script evaluates price action over a lookback window (6 bars) and compares it against three primary momentum sources:
- Relative Strength Index (RSI): Measures the speed and change of price movements.
- Stochastic Oscillator: Compares a specific closing price to a range of its prices over a certain period.
- MACD (Moving Average Convergence Divergence): Tracks the relationship between two moving averages of price.
The tool includes logic to filter out weak signals by checking the state of Exponential Moving Averages (EMA). A signal is only validated if the momentum indicators are trending in the direction of the trade while the MACD histogram remains within a specific threshold, indicating a transition in market momentum.
Settings
Stoch. Settings
- %K Length: Sets the period used for calculating the Stochastic %K line.
- %K Smoothing: Determines the internal smoothing of the %K line.
- %D Smoothing: Sets the moving average period for the %D signal line.
MACD Settings
- Fast Length: The period for the shorter-term EMA in the MACD calculation.
- Slow Length: The period for the longer-term EMA in the MACD calculation.
- Signal Length: The period for the MACD Signal line smoothing.
EMA Settings
- Fast EMA: The length of the fast EMA used for trend filtering.
- Slow EMA: The length of the slow EMA used for trend filtering.
Alerts
- Create Alerts: A boolean toggle to enable or disable automated alerts for detected divergences.
FAQ
How do I access the Divergence Indicator?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Can I use this for day trading?
Yes, the indicator can be applied to any timeframe; however, it is often most effective on higher timeframes where market noise is reduced.
What do the circles on the chart represent?
The green circles represent potential bullish momentum shifts, while red circles represent potential bearish momentum shifts based on divergence logic.
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.