pub struct HiLoActivator { /* private fields */ }Expand description
HiLo Activator — Robert Krausz’s adaptation of Linda Bradford Raschke and
Larry Connors’ “HiLo” rule, popularised by Toby Crabel. Two simple moving
averages — of the high and of the low — bracket price; the trailing stop
for a long sits at the SMA-of-low, and for a short at the SMA-of-high.
hi_sma = SMA(high, period) // potential short stop
lo_sma = SMA(low, period) // potential long stop
state-machine:
long while close > hi_sma_prev -> emit lo_sma_prev
short while close < lo_sma_prev -> emit hi_sma_prev
else: hold the previous sideComparing the close to the previous bar’s SMA avoids look-ahead and gives
the indicator a one-bar lag — the classic Crabel formulation. A long signal
fires the bar after price closes above the high-SMA; the stop then trails
at the low-SMA. The first input that fills the SMA window seeds a long.
A common configuration is a 3-period window.
§Example
use wickra_core::{Candle, Indicator, HiLoActivator};
let mut indicator = HiLoActivator::new(3).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 1.0, base - 1.0, base, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl HiLoActivator
impl HiLoActivator
Trait Implementations§
Source§impl Clone for HiLoActivator
impl Clone for HiLoActivator
Source§impl Debug for HiLoActivator
impl Debug for HiLoActivator
Source§impl Indicator for HiLoActivator
impl Indicator for HiLoActivator
Source§type Input = Candle
type Input = Candle
Type of one input data point (typically
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
Feed one new data point into the indicator and return the freshly
computed output, or
None if there is no value for this input. Read moreSource§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Source§fn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Whether the indicator has emitted at least one value since the last reset.
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable, human-readable indicator name. Used by chaining and diagnostics.
Source§fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Source§fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Opt-in fast batch: like
batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware. Read moreAuto Trait Implementations§
impl Freeze for HiLoActivator
impl RefUnwindSafe for HiLoActivator
impl Send for HiLoActivator
impl Sync for HiLoActivator
impl Unpin for HiLoActivator
impl UnsafeUnpin for HiLoActivator
impl UnwindSafe for HiLoActivator
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>>
Run the indicator over a slice of inputs in order, returning one output (or
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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