Skip to content

Commit

Permalink
double_doji
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jul 31, 2023
1 parent 4d3ac52 commit 221190d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ta_lib/patterns/src/double_doji.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use core::series::Series;

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

(close.shift(1).eq_series(&open.shift(1))
& close.shift(2).eq_series(&open.shift(2))
& close.shift(3).lt_series(&open.shift(3)))
.into()
}

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

(close.shift(1).eq_series(&open.shift(1))
& close.shift(2).eq_series(&open.shift(2))
& close.shift(3).gt_series(&open.shift(3)))
.into()
}

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

#[test]
fn test_double_doji_bullish() {
let open = vec![4.0, 4.0, 4.0, 4.0, 5.0];
let close = vec![5.0, 3.0, 4.0, 4.0, 6.0];
let expected = vec![false, false, false, false, true];

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

assert_eq!(result, expected);
}

#[test]
fn test_double_doji_bearish() {
let open = vec![4.0, 4.0, 4.0, 6.0, 5.0];
let close = vec![5.0, 5.0, 4.0, 6.0, 4.0];
let expected = vec![false, false, false, false, true];

let result = bearish(&open, &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 @@ -3,5 +3,6 @@ pub mod blockade;
pub mod bottle;
pub mod counterattack;
pub mod doji;
pub mod double_doji;
pub mod marubozu;
pub mod tasuki;

0 comments on commit 221190d

Please sign in to comment.