quantwave_core/indicators/patterns/
cdltakuri.rs1use crate::indicators::patterns::candle_settings::{
5 BODY_DOJI, CandleWindow, RollingCandleAvg, SHADOW_VERY_LONG, SHADOW_VERY_SHORT, lower_shadow,
6 real_body, upper_shadow,
7};
8use crate::traits::Next;
9
10const LOOKBACK: usize = 10; #[derive(Debug, Clone)]
13#[allow(non_camel_case_types)]
14pub struct CDLTAKURI {
15 bars_seen: usize,
16 window: CandleWindow,
17 body_doji: RollingCandleAvg,
18 shadow_vs: RollingCandleAvg,
19 shadow_vl: RollingCandleAvg,
20}
21
22impl CDLTAKURI {
23 pub fn new() -> Self {
24 Self {
25 bars_seen: 0,
26 window: CandleWindow::new(1),
27 body_doji: RollingCandleAvg::new(BODY_DOJI),
28 shadow_vs: RollingCandleAvg::new(SHADOW_VERY_SHORT),
29 shadow_vl: RollingCandleAvg::new(SHADOW_VERY_LONG),
30 }
31 }
32}
33
34impl Default for CDLTAKURI {
35 fn default() -> Self {
36 Self::new()
37 }
38}
39
40impl Next<(f64, f64, f64, f64)> for CDLTAKURI {
41 type Output = f64;
42
43 fn next(&mut self, (open, high, low, close): (f64, f64, f64, f64)) -> Self::Output {
44 self.bars_seen += 1;
45 self.window.push(open, high, low, close);
46 self.body_doji.push(open, high, low, close);
47 self.shadow_vs.push(open, high, low, close);
48 self.shadow_vl.push(open, high, low, close);
49
50 if self.bars_seen <= LOOKBACK {
51 return 0.0;
52 }
53
54 let curr = self.window.bar(0);
55
56 let out = (real_body(curr.open, curr.close) <= self.body_doji.val(0)
57 && upper_shadow(curr.open, curr.high, curr.close) < self.shadow_vs.val(0)
58 && lower_shadow(curr.open, curr.low, curr.close) > self.shadow_vl.val(0))
59 as i32
60 * 100;
61
62 out as f64
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 crate::test_pattern_parity!(
70 test_cdltakuri_parity,
71 CDLTAKURI,
72 talib_rs::pattern::cdl_takuri
73 );
74}