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 averagelong_moving_average: the window size for the long-term moving average
§Returns
Noneif the dataset is shorter thanlong_moving_average, or ifshort_moving_average >= long_moving_averageSome(vec![])if no death cross was foundSome(vec![i, ...])where eachiis 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§
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".