CCI Divergences
Jan 22, 2020

The CCI Divergences indicator is a technical analysis tool designed to automatically identify and visualize regular and hidden divergences between price action and the Commodity Channel Index (CCI). By highlighting these discrepancies, the script helps traders spot potential trend reversals or continuations through clear on-chart labels and oscillator plots.
Usage
The script can be used to identify four distinct types of divergences:
- Regular Bullish Divergence: Occurs when price makes a lower low but the CCI makes a higher low. This often suggests a potential upward reversal.
- Regular Bearish Divergence: Occurs when price makes a higher high but the CCI makes a lower high, suggesting a potential downward reversal.
- Hidden Bullish Divergence: Occurs when price makes a higher low but the CCI makes a lower low, often indicating trend continuation.
- Hidden Bearish Divergence: Occurs when price makes a lower high but the CCI makes a higher high, indicating potential trend continuation to the downside.
Traders can adjust the pivot lookback periods to filter for shorter or longer-term divergence structures. The tool also includes threshold levels at +100 and -100 to help contextualize the CCI position within overbought or oversold territory.
Details
The script calculates the standard Commodity Channel Index (CCI) and utilizes pivot point detection logic to find local highs and lows in both price and the oscillator. A divergence is confirmed when the relationship between two consecutive price pivots contradicts the relationship between the corresponding oscillator pivots. The implementation includes a lookback range filter, ensuring that the detected pivots are within a specific distance from each other to maintain relevancy.
Settings
- CCI Period: Sets the number of bars used to calculate the CCI (default is 14).
- CCI Source: Determines the price source used for the CCI calculation (default is Close).
- Pivot Lookback Right: The number of bars to the right of a pivot to confirm its peak/trough.
- Pivot Lookback Left: The number of bars to the left of a pivot to confirm its peak/trough.
- Max/Min of Lookback Range: Defines the maximum and minimum distance (in bars) allowed between two pivots for a divergence to be valid.
- Plotting Toggles: Individual checkboxes to enable or disable the visualization of Regular Bullish, Hidden Bullish, Regular Bearish, and Hidden Bearish divergences.
FAQ
How do I use the alerts in this script?
You can set up alert conditions for when the CCI crosses the +/- 100 levels or when any of the four types of divergences are detected by the script.
What is the difference between regular and hidden divergences?
Regular divergences typically signal a potential trend reversal, while hidden divergences generally suggest that the current trend is likely to continue.
How can I access this tool?
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.