Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed May 2, 2024
1 parent 07ee5d6 commit 72d4848
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions ta_lib/strategies/pulse/src/chop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,118 @@ impl Pulse for ChopPulse {
&data.atr(self.atr_period),
self.period,
);

let lower_chop = CHOP_MIDDLE_LINE + self.threshold;

(chop.slt(&lower_chop), chop.slt(&lower_chop))
}
}

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

#[test]
fn test_pulse_chop() {
let pulse = ChopPulse::new(6.0, 1.0, 0.0);
let data = VecDeque::from([
OHLCV {
ts: 1679825700,
open: 5.993,
high: 6.000,
low: 5.983,
close: 5.997,
volume: 100.0,
},
OHLCV {
ts: 1679826000,
open: 5.997,
high: 6.001,
low: 5.989,
close: 6.001,
volume: 100.0,
},
OHLCV {
ts: 1679826300,
open: 6.001,
high: 6.0013,
low: 5.993,
close: 6.007,
volume: 100.0,
},
OHLCV {
ts: 1679826600,
open: 6.007,
high: 6.008,
low: 5.980,
close: 5.992,
volume: 100.0,
},
OHLCV {
ts: 1679826900,
open: 5.992,
high: 5.993,
low: 5.976,
close: 5.980,
volume: 100.0,
},
OHLCV {
ts: 1679827200,
open: 5.980,
high: 5.986,
low: 5.966,
close: 5.969,
volume: 100.0,
},
OHLCV {
ts: 1679827500,
open: 5.969,
high: 5.969,
low: 5.943,
close: 5.946,
volume: 100.0,
},
OHLCV {
ts: 1679827800,
open: 5.946,
high: 5.960,
low: 5.939,
close: 5.953,
volume: 100.0,
},
OHLCV {
ts: 1679828100,
open: 5.953,
high: 5.961,
low: 5.937,
close: 5.939,
volume: 100.0,
},
OHLCV {
ts: 1679828400,
open: 5.939,
high: 5.945,
low: 5.919,
close: 5.943,
volume: 100.0,
},
]);
let series = OHLCVSeries::from_data(&data);

let (long_signal, short_signal) = pulse.assess(&series);

let expected_long_signal = vec![
true, true, false, false, false, false, true, true, true, true,
];
let expected_short_signal = vec![
true, true, false, false, false, false, true, true, true, true,
];

let result_long_signal: Vec<bool> = long_signal.into();
let result_short_signal: Vec<bool> = short_signal.into();

assert_eq!(result_long_signal, expected_long_signal);
assert_eq!(result_short_signal, expected_short_signal);
}
}

0 comments on commit 72d4848

Please sign in to comment.