pub struct CCI { /* private fields */ }Expand description
Commodity Channel Index (CCI) Indicator
CCI measures how far the current price deviates from its statistical average. It’s used to identify cyclical trends and overbought/oversold conditions.
Formula:
- Typical Price = (High + Low + Close) / 3
- SMA of Typical Price = Sum(TP) / Period
- Mean Deviation = Sum(|TP - SMA|) / Period
- CCI = (TP - SMA) / (0.015 × Mean Deviation)
The constant 0.015 ensures about 70-80% of CCI values fall between -100 and +100.
Interpretation:
- Above +100: Overbought, potential sell signal
- Below -100: Oversold, potential buy signal
- Above +200: Extremely overbought
- Below -200: Extremely oversold
Implementations§
Source§impl CCI
impl CCI
Sourcepub fn with_period(period: usize) -> Result<Self, CCIError>
pub fn with_period(period: usize) -> Result<Self, CCIError>
Create a new CCI calculator with custom period
Sourcepub fn with_thresholds(
period: usize,
overbought: f64,
oversold: f64,
extreme_overbought: f64,
extreme_oversold: f64,
) -> Result<Self, CCIError>
pub fn with_thresholds( period: usize, overbought: f64, oversold: f64, extreme_overbought: f64, extreme_oversold: f64, ) -> Result<Self, CCIError>
Create a new CCI calculator with custom period and thresholds
Sourcepub fn with_config(config: CCIConfig) -> Self
pub fn with_config(config: CCIConfig) -> Self
Create a new CCI calculator with custom configuration
Sourcepub fn calculate(&mut self, input: CCIInput) -> Result<CCIOutput, CCIError>
pub fn calculate(&mut self, input: CCIInput) -> Result<CCIOutput, CCIError>
Calculate CCI for the given input
Sourcepub fn calculate_batch(
&mut self,
inputs: &[CCIInput],
) -> Result<Vec<CCIOutput>, CCIError>
pub fn calculate_batch( &mut self, inputs: &[CCIInput], ) -> Result<Vec<CCIOutput>, CCIError>
Calculate CCI for a batch of inputs
Sourcepub fn market_condition(&self) -> CCIMarketCondition
pub fn market_condition(&self) -> CCIMarketCondition
Get current market condition
Sourcepub fn is_overbought(&self, cci: f64) -> bool
pub fn is_overbought(&self, cci: f64) -> bool
Check if currently overbought
Sourcepub fn is_oversold(&self, cci: f64) -> bool
pub fn is_oversold(&self, cci: f64) -> bool
Check if currently oversold
Sourcepub fn is_extreme_condition(&self, cci: f64) -> bool
pub fn is_extreme_condition(&self, cci: f64) -> bool
Check if in extreme condition
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CCI
impl RefUnwindSafe for CCI
impl Send for CCI
impl Sync for CCI
impl Unpin for CCI
impl UnwindSafe for CCI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more