Indicators/probuilder · probacktest · proorder · proscreener

DivergenceCCI

DivergenceCCI in ProBuilder detects bullish and bearish divergences between price and the CCI, returning +1, -1, or 0. Syntax, parameters, and examples.

Syntax

probuilder
DivergenceCCI[CCIperiod, LowCCIthreshold, HighCCIthreshold, Bars]

The instruction takes no price argument; all four parameters go inside the square brackets.

Parameters

NameTypeDefaultDescription
CCIperiodinteger20Period of the underlying CCI calculation.
LowCCIthresholdinteger-100Lower CCI level, the conventional oversold zone where bullish divergences are searched.
HighCCIthresholdinteger100Upper CCI level, the conventional overbought zone where bearish divergences are searched.
Barsinteger20Number of recent bars examined for a divergence pattern.

Formula

The detector compares the direction of price extremes with the direction of CCI extremes over the last Bars bars:

code
Bullish divergence: price makes lower lows while the CCI makes higher lows  -> +1
Bearish divergence: price makes higher highs while the CCI makes lower highs -> -1
No divergence detected                                                       -> 0

The thresholds restrict detection to CCI swings that reached the oversold or overbought zones, filtering out shallow oscillations near zero.

How it works

A divergence occurs when price and its oscillator disagree. If price grinds to a new low but the CCI bottoms at a higher level than before, selling momentum is fading even though the chart still points down; that is the bullish case. The bearish case is the mirror image at new price highs.

DivergenceCCI packages that comparison into a single value per bar. Internally it computes a CCI with the given period, locates the relevant swings within the detection window, checks them against the thresholds, and reports the outcome as +1, -1, or 0. The output is a discrete signal series rather than a continuous oscillator, which is why it is commonly displayed as a histogram.

The signal marks a weakening of the current move, not a completed reversal. Standard practice is to treat it as a warning or a setup condition and require confirmation, such as a trend filter or a price trigger, before acting.

Examples

Example 1, Divergence signal histogram (Indicator)

probuilder
// Default settings: 20-period CCI, -100/+100 zones, 20-bar detection window
i = DivergenceCCI[20, -100, 100, 20]
return i style(histogram)

Plots the raw signal as a histogram: bars at +1 mark bullish divergences, bars at -1 mark bearish divergences, and empty stretches mean no divergence was detected.

Example 2, Bullish divergence scan (ProScreener)

probuilder
// List instruments printing a bullish CCI divergence right now
d = DivergenceCCI[20, -100, 100, 20]
c = CCI[20]
SCREENER[d = 1](c AS "CCI 20")

Returns instruments where the detector currently reports a bullish divergence, with the CCI value shown for context.

Example 3, Divergence entry with trend filter (ProBacktest)

probuilder
// Buy bullish divergences only above the long-term average
trend = Average[200](close)
signal = DivergenceCCI[20, -100, 100, 20]

IF NOT LongOnMarket AND close > trend AND signal = 1 THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP %LOSS 2
ENDIF
IF LongOnMarket AND signal = -1 THEN
  SELL AT MARKET
ENDIF

Takes bullish divergences as pullback entries within a larger uptrend and uses a bearish divergence as the exit trigger, with a protective stop attached at entry.

Interpretation

  • +1, bullish divergence. Price set a lower low while the CCI set a higher low from the oversold zone. Downward momentum is fading; sometimes precedes an upward reversal.
  • -1, bearish divergence. Price set a higher high while the CCI set a lower high from the overbought zone. Upward momentum is fading.
  • 0, no signal. No qualifying divergence inside the detection window.

Divergences can stack: a trending market may print several consecutive divergences before actually turning. The signal quality improves when it aligns with the higher-timeframe trend rather than fighting it.

Common errors and gotchas

  • Adding a price argument. DivergenceCCI[20, -100, 100, 20](close) does not match the documented signature. The instruction takes only the four bracket parameters.
  • Mismatched parameters between charts. When a separate CCI panel uses a different period than CCIperiod, the divergences flagged by the detector will not line up with swings visible on that panel. Keep the periods synchronized.
  • Threshold order. The low threshold comes before the high one. DivergenceCCI[20, 100, -100, 20] compiles but inverts the zones and effectively disables meaningful detection.
  • Trading every signal. Divergence against a strong trend fails often. Combining the signal with a trend or strength filter, as in Example 3, is the standard mitigation.
  • DivergenceMACD, the same detector built on the MACD.
  • DivergenceRSI, the same detector built on RSI.
  • CCI, the underlying Commodity Channel Index.
  • RSI, bounded momentum oscillator with comparable divergence logic.
  • MACD, trend-following momentum histogram.
  • Stochastic, range-position oscillator also used for divergence analysis.
  • Momentum, raw N-bar price change.
  • STYLE, rendering instruction used to draw the signal as a histogram.