quantwave_core/indicators/incremental/
cdl_doji.rs1use crate::indicators::patterns::candle_settings::{BODY_DOJI, RollingCandleAvg};
4use crate::traits::Next;
5
6const LOOKBACK: usize = 10;
7
8#[derive(Debug, Clone)]
9#[allow(non_camel_case_types)]
10pub struct CDLDOJI {
11 bars_seen: usize,
12 hl_avg: RollingCandleAvg,
13}
14
15impl CDLDOJI {
16 pub fn new() -> Self {
17 Self {
18 bars_seen: 0,
19 hl_avg: RollingCandleAvg::new(BODY_DOJI),
20 }
21 }
22}
23
24impl Default for CDLDOJI {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl Next<(f64, f64, f64, f64)> for CDLDOJI {
31 type Output = f64;
32
33 fn next(&mut self, (open, high, low, close): (f64, f64, f64, f64)) -> Self::Output {
34 self.bars_seen += 1;
35 self.hl_avg.push(open, high, low, close);
36
37 if self.bars_seen <= LOOKBACK {
38 return 0.0;
39 }
40
41 let body = (close - open).abs();
42 let thresh = self.hl_avg.val(0);
43
44 100.0_f64.copysign(thresh - body).max(0.0)
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51 crate::test_pattern_parity!(test_cdl_doji_parity, CDLDOJI, talib_rs::pattern::cdl_doji);
52}