pub struct Counterattack { /* private fields */ }Expand description
Counterattack — a 2-bar reversal where the second bar storms back to close right where the first bar closed. A long candle runs with the trend, then an opposite-coloured long candle opens far in the trend direction and rallies (or sells off) all the way back to the prior close — the two closes meeting forms the “counterattack line”.
long bodies = |close − open| >= 0.5 * (high − low) (both bars)
equal closes = |close2 − close1| <= tol * mean(range1, range2)
bullish (+1.0): bar1 black (down), bar2 white (up), equal closes
bearish (−1.0): bar1 white (up), bar2 black (down), equal closesOutput is +1.0 bullish, −1.0 bearish, and 0.0 when the bodies are short,
the colours match, or the closes are not level. The first bar always returns
0.0 because the two-bar window is not yet filled. equal_tolerance defaults
to 0.05 (TA-Lib’s CDLCOUNTERATTACK “equal” factor — 5 % of the mean bar
range) and must lie in [0, 1). The body-length test uses a fixed half-range
fraction rather than TA-Lib’s rolling body average, matching the geometric
house style of this pattern family. Pattern-shape check only — no trend filter
is applied; combine with a trend indicator for actionable signals.
§Signed ±1 encoding
This detector emits the uniform candlestick sign convention shared across the
pattern family — +1.0 bullish, −1.0 bearish, 0.0 no pattern — so it
drops straight into a machine-learning feature matrix where the bullish and
bearish variants occupy a single dimension.
§Example
use wickra_core::{Candle, Counterattack, Indicator};
let mut indicator = Counterattack::new();
// Bullish: a long black bar, then a long white bar closing at the same level.
indicator.update(Candle::new(20.0, 20.1, 14.9, 15.0, 1.0, 0).unwrap());
let out = indicator
.update(Candle::new(10.0, 15.1, 9.9, 15.0, 1.0, 1).unwrap());
assert_eq!(out, Some(1.0));Implementations§
Source§impl Counterattack
impl Counterattack
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a Counterattack detector with the default 5 % equal-close tolerance.
Sourcepub fn with_tolerance(equal_tolerance: f64) -> Result<Self>
pub fn with_tolerance(equal_tolerance: f64) -> Result<Self>
Construct a Counterattack detector with a custom equal-close tolerance.
equal_tolerance is the fraction of the mean bar range within which the
two closes must agree and must lie in [0, 1).
Sourcepub fn equal_tolerance(&self) -> f64
pub fn equal_tolerance(&self) -> f64
Configured equal-close tolerance.
Trait Implementations§
Source§impl Clone for Counterattack
impl Clone for Counterattack
Source§fn clone(&self) -> Counterattack
fn clone(&self) -> Counterattack
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Counterattack
impl Debug for Counterattack
Source§impl Default for Counterattack
impl Default for Counterattack
Source§impl Indicator for Counterattack
impl Indicator for Counterattack
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for Counterattack
impl RefUnwindSafe for Counterattack
impl Send for Counterattack
impl Sync for Counterattack
impl Unpin for Counterattack
impl UnsafeUnpin for Counterattack
impl UnwindSafe for Counterattack
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more