Zigzag Trend/Divergence Detector
Sep 11, 2021

The Zigzag Trend/Divergence Detector indicator provides a combined sentiment analysis based on price action trends and momentum divergences. It aims to simplify decision-making during pullbacks or trending phases by identifying whether a movement is a continuation, a standard divergence, or a hidden divergence.
Usage
The indicator identifies pivot highs and lows using a Zigzag algorithm and compares them with a selected oscillator to detect momentum shifts. By combining divergence types with Supertrend-based bias, the tool outputs a sentiment rating.
- Continuation (C): Suggests the current trend is likely to persist.
- Divergence (D): Indicates a potential trend reversal.
- Hidden Divergence (H): Often signals a trend continuation after a pullback.
- Indeterminate (I): Occurs when price and momentum signals are non-conforming.
Users can choose to color bars based on the trend bias and display a statistical table that logs the history of detected signals.
Details
The script uses a Supertrend calculation to establish the underlying trend bias. Divergence is calculated by observing the difference between subsequent price pivots and corresponding oscillator pivots. Because oscillators do not always peak at the exact same bar as price, the tool includes a "Confirmed Pivots" setting to ensure calculations are based on established historical data rather than real-time fluctuations.
Settings
Zigzag
- Close Prices: Toggles between using high/low prices or close prices for zigzag calculation.
- Confirmed Pivots: If enabled, the indicator only processes pivots that are fully confirmed, reducing "repainting" at the cost of slight lag.
- Length: Adjusts the sensitivity of the zigzag; higher values filter out minor price noise.
Oscillator
- Source: Select from a wide variety of oscillators including RSI, MACD, CCI, MFI, and more.
- External Source: Allows the use of a custom external indicator for divergence detection.
- Length/Short/Long: Configures the periods for the selected oscillator.
Supertrend (Trend Bias)
- Pivot History: Determines how many previous pivots are considered for the trend calculation.
- ATR Length & Multiplier: Standard inputs for the Supertrend volatility-based trend filter.
- Color Candles: Highlights the chart candles based on the current Supertrend direction.
Stats and Display
- Max Rows: Limits the number of entries in the on-screen data table.
- Display Filters: Toggles visibility for Continuation, Divergence, Hidden Divergence, or Indeterminate labels.
FAQ
How do I interpret the "I" label? The "I" stands for Indeterminate. It appears when the relationship between price pivots and oscillator movement does not meet the specific criteria for standard or hidden divergence.
Why does the zigzag line change occasionally? Unless "Confirmed Pivots" is enabled, the latest leg of the zigzag is dynamic and will adjust as new price extremes are reached.
How do I access Zigzag Trend/Divergence Detector? 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.