Skip to main content

DeathCross

Trait DeathCross 

Source
pub trait DeathCross {
    // Required method
    fn h_death_cross(
        &self,
        short_moving_average: usize,
        long_moving_average: usize,
    ) -> Option<Vec<usize>>;
}
Expand description

Identifies the indices where a death cross occurs in a dataset.

A death cross occurs when a short-term moving average crosses below a long-term moving average. This is commonly interpreted as a bearish signal in financial analysis.

§Parameters

  • short_moving_average: the window size for the short-term moving average
  • long_moving_average: the window size for the long-term moving average

§Returns

  • None if the dataset is shorter than long_moving_average, or if short_moving_average >= long_moving_average
  • Some(vec![]) if no death cross was found
  • Some(vec![i, ...]) where each i is the data index where a cross occurred

§Example

let data = vec![5.0, 6.0, 8.0, 6.0, 4.0, 2.0, 1.0]; let crosses = data.h_death_cross(2, 3); assert!(crosses.unwrap().len() > 0);

A perfectly linear decreasing sequence like vec![6,5,4,3,2,1] will return Some(vec![]) because the short and long MAs are always equal — no crossover occurs.

Required Methods§

Source

fn h_death_cross( &self, short_moving_average: usize, long_moving_average: usize, ) -> Option<Vec<usize>>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<D> DeathCross for [D]
where D: Copy + Into<f64>,

Source§

fn h_death_cross( &self, short_moving_average: usize, long_moving_average: usize, ) -> Option<Vec<usize>>

Implementors§