All indicators

Realtime Divergence for Any Indicator

Aug 26, 2023

Static chart image
SignalsOscillatorsDivergencesPivot Based (Retrospective)

The Realtime Divergence for Any Indicator tool identifies and displays both historical and real-time bullish and bearish divergences between price action and any oscillating indicator. It provides traders with precise control over divergence identification, using solid lines for confirmed signals and dashed lines for potential, real-time setups.

Usage

The indicator can be used to spot four primary types of divergences: Regular Bullish, Hidden Bullish, Regular Bearish, and Hidden Bearish. By default, it plots confirmed historical divergences once all pivot bars have closed.

To use the tool effectively:

  • Potential Divergences: Enable "Realtime Potential Divergences" to see dashed lines for emerging setups. This includes setups where the right-side pivot bar is still forming or lacks sufficient right-side confirmation bars.
  • Price vs. Oscillator: Use the "Apply To Price Chart" toggle to switch the visual lines between the main price chart and the indicator pane.
  • Filtering: Adjust the "Min/Max Length" to filter out divergences that are too short or too wide to be considered significant.

Details

The script utilizes a sophisticated pivot detection algorithm with two distinct patterns:

  • Type 1: A strict pyramid pattern where bars must strictly ascend/descend.
  • Type 2: A more flexible pattern that permits side bars to be equal in value to the pivot bar.

The "Real-time" aspect is calculated in three stages:

  1. No right-side bars present for the pivot.
  2. No right-side bars present, but the pivot bar itself has closed.
  3. Right-side bars are present, but the right-most bar of the confirmation period has not yet closed.

Settings

Sources

  • Price Chart Bulls/Bears Source: The data source (e.g., Low, High) used for bullish and bearish price calculations.
  • Oscillator Chart Bulls/Bears Source: The data source used for the corresponding oscillating indicator.

General Display Settings

  • Apply To Price Chart: Toggles whether lines appear on the price chart or the indicator.
  • Bull/Bear/Hidden Lines/Labels: Toggles for various types of divergence visuals.

Pivots

  • Pivot Pattern: Selection between "Type 1" (Pyramid) and "Type 2" (Standard).
  • Right/Left Side Bars: Defines the number of bars required on either side of a pivot to confirm its validity.

Divergences

  • Min/Max Length: The minimum and maximum distance between the two pivots of a divergence.
  • Intersection Allowance: Determines how much "price/oscillator penetration" is allowed between the two pivots before a divergence is invalidated.
  • Normalization Factor: A setting used to define the "angle" of slopes for exclusion purposes.

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.

Why do some divergence lines disappear from the left side of the chart?

TradingView has a technical limit on the number of lines a single script can draw (currently 500). If your settings generate many signals, older lines are automatically removed to display newer ones.

What should I do if I get a "max_bars_back" error?

This typically occurs when no divergence is found within the first 244 bars of data. You can try loosening your pivot or length settings to find an earlier signal, which allows Pine Script to properly calculate the required buffer.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.