pub struct Reflex { /* private fields */ }Expand description
Ehlers’ Reflex — a near-zero-lag oscillator that measures how far the smoothed price has deviated from the straight line connecting its endpoints over the lookback.
From John Ehlers, “Reflex: A New Zero-Lag Indicator” (Stocks & Commodities, Feb 2020):
Filt = SuperSmoother(price, period)
slope = (Filt[period] − Filt[0]) / period (line over the window)
sum = mean over i=1..period of ( Filt[0] + i·slope − Filt[i] )
ms = 0.04·sum² + 0.96·ms[−1] (adaptive normaliser)
Reflex = sum / sqrt(ms) (0 if ms == 0)Reflex fits a straight line across the SuperSmoothed price over period bars
and averages the deviation of the curve from that line. Because the line uses
both endpoints, the measure has almost no lag — it crosses zero essentially at
the cycle turns. The adaptive mean-square normaliser rescales the output to a
roughly ±3 range regardless of price, so the same thresholds work on any
instrument. Its sibling Trendflex uses the deviation from
the current value instead of the line, making it trend- rather than
cycle-sensitive.
The first value lands after period + 1 SuperSmoothed samples. Each update
is O(period).
§Example
use wickra_core::{Indicator, Reflex};
let mut indicator = Reflex::new(20).unwrap();
let mut last = None;
for i in 0..120 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Indicator for Reflex
impl Indicator for Reflex
Source§fn update(&mut self, price: f64) -> Option<f64>
fn update(&mut self, price: f64) -> 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 Reflex
impl RefUnwindSafe for Reflex
impl Send for Reflex
impl Sync for Reflex
impl Unpin for Reflex
impl UnsafeUnpin for Reflex
impl UnwindSafe for Reflex
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