Skip to content

Commit

Permalink
marubozu
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jul 27, 2023
1 parent 4715741 commit 248d3d7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ta_lib/patterns/src/marubozu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use core::series::Series;

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

close.shift(1) > open.shift(1)
&& high.shift(1) == close.shift(1)
&& low.shift(1) == open.shift(1)
}

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

close.shift(1) < open.shift(1)
&& high.shift(1) == open.shift(1)
&& low.shift(1) == close.shift(1)
}

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

#[test]
fn test_marubozu_bullish() {
let open = vec![4.0, 4.0, 4.0, 4.0, 4.0];
let high = vec![3.0, 3.0, 3.0, 3.0, 3.0];
let low = vec![1.0, 1.0, 1.0, 1.0, 1.0];
let close = vec![2.0, 2.5, 2.0, 1.5, 2.0];
let expected = vec![true, true, true, true, true];

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

assert_eq!(result, expected);
}

#[test]
fn test_marubozu_bearish() {
let open = vec![4.0, 4.0, 4.0, 4.0, 4.0];
let high = vec![3.0, 3.0, 3.0, 3.0, 3.0];
let low = vec![1.0, 1.0, 1.0, 1.0, 1.0];
let close = vec![2.0, 2.5, 2.0, 1.5, 2.0];
let expected = vec![true, true, true, true, true];

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

assert_eq!(result, expected);
}
}

0 comments on commit 248d3d7

Please sign in to comment.