Struct CCI

Source
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:

  1. Typical Price = (High + Low + Close) / 3
  2. SMA of Typical Price = Sum(TP) / Period
  3. Mean Deviation = Sum(|TP - SMA|) / Period
  4. 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

Source

pub fn new() -> Self

Create a new CCI calculator with default configuration (period=20)

Source

pub fn with_period(period: usize) -> Result<Self, CCIError>

Create a new CCI calculator with custom period

Source

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

Source

pub fn with_config(config: CCIConfig) -> Self

Create a new CCI calculator with custom configuration

Source

pub fn calculate(&mut self, input: CCIInput) -> Result<CCIOutput, CCIError>

Calculate CCI for the given input

Source

pub fn calculate_batch( &mut self, inputs: &[CCIInput], ) -> Result<Vec<CCIOutput>, CCIError>

Calculate CCI for a batch of inputs

Source

pub fn reset(&mut self)

Reset the calculator state

Source

pub fn get_state(&self) -> &CCIState

Get current state (for serialization/debugging)

Source

pub fn set_state(&mut self, state: CCIState)

Restore state (for deserialization)

Source

pub fn market_condition(&self) -> CCIMarketCondition

Get current market condition

Source

pub fn is_overbought(&self, cci: f64) -> bool

Check if currently overbought

Source

pub fn is_oversold(&self, cci: f64) -> bool

Check if currently oversold

Source

pub fn is_extreme_condition(&self, cci: f64) -> bool

Check if in extreme condition

Trait Implementations§

Source§

impl Default for CCI

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.