Realtime Divergence for Any Indicator
Jun 19, 2022

The Realtime Divergence for Any Indicator tool acts as a versatile companion for any oscillating indicator, identifying both regular and hidden divergences in real time. By analyzing potential pivots before they are fully confirmed, this script provides early indications of trend reversals or continuations, helping traders anticipate market shifts.
Usage
This script is designed to be added to an existing oscillator (such as RSI, MACD, or Stochastic). To use it effectively:
- Indicator Add-on: Set the "Source Input" to the plot of your chosen oscillator.
- Overlay Mode: Use the "Overlay Chart" toggle to display the divergence lines directly on the price action rather than the oscillator pane.
- Real-time Identification: Dash lines represent potential divergences forming in real time, while solid lines indicate confirmed divergences where the pivot point has been fully established.
Details
The script identifies four primary types of divergences:
- Regular Bullish: Lower lows in price with higher lows in the oscillator.
- Regular Bearish: Higher highs in price with lower highs in the oscillator.
- Hidden Bullish: Higher lows in price with lower lows in the oscillator.
- Hidden Bearish: Lower highs in price with higher highs in the oscillator.
It utilizes advanced filtering logic, including "Intersection Allowance," which prevents divergences from being valid if the price or oscillator crosses the projected trendline too aggressively. The "Best Slope" feature ensures that if multiple potential divergence lines exist for the same pivot, only the most technically significant one is displayed.
Settings
General Settings
- Overlay Chart: Displays divergence lines on the main price chart instead of the oscillator pane.
- Source Input: The specific indicator data point (e.g., RSI value) to analyze for divergences.
- Pivot Lookback (Right/Left): Determines the number of bars required to confirm a pivot point.
- Lookback Range (Min/Max): Sets the minimum and maximum horizontal distance (in bars) allowed between two pivots to form a divergence.
Filter Settings
- Bars Allowing Intersection: The number of bars at the start/end of a line where intersection is ignored.
- Allowance for Oscillator/Price Intersection: The percentage threshold allowed for data to deviate beyond the divergence line before it is invalidated.
- Allowance for Misalignment: The number of bars permitted for the price pivot and oscillator pivot to be out of sync.
Display & Alerts
- Display Plots: Toggles for Bullish, Bearish, and Hidden divergence lines/flags.
- Real Time Potential Divergences: Enables the calculation and display of dashed lines for forming pivots.
- Real Time Potential Divergence Alerts: Enables alert triggers for unconfirmed, real-time setups.
FAQ
How do I access Realtime Divergence for Any 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 with any indicator?
Yes, as long as the indicator provides a series output (like an oscillator line), you can select it via the "Source Input" field in the settings.
Why do some divergence lines disappear?
Dashed lines represent real-time "potential" divergences. If the price or oscillator moves in a way that breaks the divergence logic before the pivot is confirmed, the potential line will be removed. Solid lines are confirmed and will remain on the chart.
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.