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§fn clone(&self) -> HiLoActivator
fn clone(&self) -> HiLoActivator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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 the indicator is still warming up.Source§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.Auto 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