Skip to content

Commit

Permalink
hexad
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Aug 1, 2023
1 parent c987c49 commit d40a350
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions ta_lib/patterns/src/hexad.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use core::series::Series;

pub fn bullish(open: &[f64], high: &[f64], close: &[f64]) -> Vec<bool> {
let open = Series::from(open);
let high = Series::from(high);
let close = Series::from(close);

(close.gt(&open)
& close.shift(1).gt(&open.shift(1))
& close.shift(2).gt(&open.shift(2))
& close.shift(3).lt(&open.shift(3))
& close.shift(4).lt(&open.shift(4))
& close.shift(5).lt(&open.shift(5))
& close.gt(&high.shift(5)))
.into()
}

pub fn bearish(open: &[f64], low: &[f64], close: &[f64]) -> Vec<bool> {
let open = Series::from(open);
let low = Series::from(low);
let close = Series::from(close);

(close.lt(&open)
& close.shift(1).lt(&open.shift(1))
& close.shift(2).lt(&open.shift(2))
& close.shift(3).gt(&open.shift(3))
& close.shift(4).gt(&open.shift(4))
& close.shift(5).gt(&open.shift(5))
& close.lt(&low.shift(5)))
.into()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_hexad_bullish() {
let open = vec![4.0, 3.0, 4.0, 3.0, 5.0];
let high = vec![3.5, 2.5, 3.5, 2.5, 4.5];
let close = vec![4.5, 4.0, 5.0, 4.5, 5.5];
let expected = vec![false, false, false, false, false];

let result = bullish(&open, &high, &close);

assert_eq!(result, expected);
}

#[test]
fn test_hexad_bearish() {
let open = vec![4.0, 5.0, 4.0, 5.0, 4.0];
let low = vec![4.5, 5.5, 4.5, 5.5, 4.5];
let close = vec![3.5, 4.0, 3.5, 4.0, 3.5];
let expected = vec![false, false, false, false, false];

let result = bearish(&open, &low, &close);

assert_eq!(result, expected);
}
}
1 change: 1 addition & 0 deletions ta_lib/patterns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod counterattack;
pub mod doji;
pub mod double_doji;
pub mod h;
pub mod hexad;
pub mod marubozu;
pub mod on_neck;
pub mod shrinking;
Expand Down

0 comments on commit d40a350

Please sign in to comment.