pub struct DoubleTopBottom { /* private fields */ }Expand description
Double Top / Double Bottom — a two-peak (or two-trough) reversal pattern.
The detector tracks confirmed swing pivots (a non-repainting percent-threshold
zig-zag, [SWING_THRESHOLD] = 5%). A pattern is recognised on the bar that
confirms the second matching extreme:
double top : … High₁ , Low , High₂ with High₁ ≈ High₂ → -1 (bearish)
double bottom : … Low₁ , High , Low₂ with Low₁ ≈ Low₂ → +1 (bullish)Two extremes count as the same level when they are within
[LEVEL_TOLERANCE] (3%) of each other. Because pivots strictly alternate
high/low, the trough between the twin tops (or the peak between the twin
bottoms) is guaranteed to sit beyond both, so no extra separation check is
needed.
Output is +1.0 for a double bottom, -1.0 for a double top, and 0.0 on
every other bar (including warmup and bars that confirm a pivot which does
not complete the pattern). Like the candlestick family this detector never
returns None.
§Example
use wickra_core::{Candle, DoubleTopBottom, Indicator};
let mut indicator = DoubleTopBottom::new();
for (i, &(high, low)) in [
(100.0, 99.5),
(120.0, 119.5),
(110.0, 100.0), // confirms the first top at 120
(120.0, 119.0), // confirms the trough at 100
(115.0, 110.0), // confirms the second top at 120 → double top
]
.iter()
.enumerate()
{
let c = Candle::new(low, high, low, low, 1.0, i as i64).unwrap();
let signal = indicator.update(c).unwrap();
if i == 4 {
assert_eq!(signal, -1.0);
}
}Implementations§
Trait Implementations§
Source§impl Clone for DoubleTopBottom
impl Clone for DoubleTopBottom
Source§fn clone(&self) -> DoubleTopBottom
fn clone(&self) -> DoubleTopBottom
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 DoubleTopBottom
impl Debug for DoubleTopBottom
Source§impl Default for DoubleTopBottom
impl Default for DoubleTopBottom
Source§impl Indicator for DoubleTopBottom
impl Indicator for DoubleTopBottom
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 DoubleTopBottom
impl RefUnwindSafe for DoubleTopBottom
impl Send for DoubleTopBottom
impl Sync for DoubleTopBottom
impl Unpin for DoubleTopBottom
impl UnsafeUnpin for DoubleTopBottom
impl UnwindSafe for DoubleTopBottom
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