The DivergenceCCI function in ProBuilder language is designed to identify and return signals of bullish and bearish divergences between the Commodity Channel Index (CCI) and the price movements of a stock. Divergences are important as they can indicate potential reversals in the current price trend.
Syntax:
DivergenceCCI[CCIperiod, LowCCIthreshold, HighCCIthreshold, Bars]
- CCIperiod: The number of periods used for calculating the CCI. Default is 20.
- LowCCIthreshold: The lower threshold of the CCI, typically used to identify oversold conditions. Default is -100.
- HighCCIthreshold: The upper threshold of the CCI, typically used to identify overbought conditions. Default is 100.
- Bars: The number of bars to consider for detecting potential divergences. Default is 20.
Calculation and Interpretation:
The DivergenceCCI function detects:
- Bullish Divergence: Occurs when the price records new lows while the CCI begins to rise. This scenario suggests a weakening of the downward trend and a potential upward reversal. The function returns +1 in this case.
- Bearish Divergence: Occurs when the price records new highs while the CCI begins to fall. This indicates a weakening of the upward trend and a potential downward reversal. The function returns -1 in this case.
- If no divergence is detected, the function returns 0.
Example:
i = DivergenceCCI[20, -100, 100, 20]
return i style(histogram)
This example sets up the DivergenceCCI function with default parameters and applies it to a histogram style chart. It will help visualize the bullish and bearish divergence signals.
Tip: When analyzing divergences using both a price chart and a CCI chart, ensure that the CCI and DivergenceCCI parameters are synchronized for accurate comparison and analysis.