Skip to main content

RegimeDetector

Struct RegimeDetector 

Source
pub struct RegimeDetector { /* private fields */ }
Expand description

Main indicator-based regime detection engine.

Feeds OHLC bars through ADX, ATR, Bollinger Bands, and dual-EMA indicators, then scores each regime possibility to produce a classification with confidence.

Includes a stability filter to prevent regime whipsawing.

§Example

use indicators::{RegimeDetector, RegimeConfig, MarketRegime};

let mut detector = RegimeDetector::crypto_optimized();

// Feed OHLC bars
for i in 0..300 {
    let price = 100.0 + i as f64 * 0.5;
    let result = detector.update(price + 1.0, price - 1.0, price);
    if detector.is_ready() {
        println!("Regime: {} (conf: {:.0}%)", result.regime, result.confidence * 100.0);
    }
}

Implementations§

Source§

impl RegimeDetector

Source

pub fn new(config: RegimeConfig) -> Self

Create a new detector with the given configuration

Source

pub fn default_config() -> Self

Create with default config

Source

pub fn crypto_optimized() -> Self

Create optimized for crypto markets

Source

pub fn conservative() -> Self

Create with conservative config

Source

pub fn update(&mut self, high: f64, low: f64, close: f64) -> RegimeConfidence

Update with new OHLC bar and get the regime classification.

Returns a RegimeConfidence with the detected regime, confidence score, and supporting indicator metrics.

The detector requires a warmup period (determined by the longest indicator period) before it starts producing meaningful classifications. During warmup, it returns MarketRegime::Uncertain with zero confidence.

Source

pub fn is_ready(&self) -> bool

Check if detector has enough data to classify regime.

All indicators must be warmed up before the detector can produce meaningful results.

Source

pub fn current_regime(&self) -> MarketRegime

Get current detected regime

Source

pub fn recommended_strategy(&self) -> RecommendedStrategy

Get recommended strategy for current regime

Source

pub fn bars_in_current_regime(&self) -> usize

Get number of bars in current regime

Source

pub fn adx_value(&self) -> Option<f64>

Get ADX value

Source

pub fn atr_value(&self) -> Option<f64>

Get ATR value

Source

pub fn config(&self) -> &RegimeConfig

Get current config

Source

pub fn set_config(&mut self, config: RegimeConfig)

Update config (resets internal state)

Source

pub fn regime_history(&self) -> &VecDeque<MarketRegime>

Get the regime history (most recent at the back)

Source

pub fn last_close(&self) -> Option<f64>

Get the last close price

Trait Implementations§

Source§

impl Debug for RegimeDetector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.