pub struct WaveTrend { /* private fields */ }Expand description
LazyBear’s Wave Trend Oscillator — a two-line momentum gauge built from
the typical price and three cascaded EMAs.
For each candle let ap_t = (high + low + close) / 3:
esa_t = EMA(ap, channel_period)
d_t = EMA(|ap − esa|, channel_period)
ci_t = (ap_t − esa_t) / (0.015 * d_t)
wt1_t = EMA(ci, average_period)
wt2_t = SMA(wt1, signal_period)Bullish trigger: wt1 crossing above wt2 from an oversold region
(typically wt1 < -60); bearish trigger: the mirror crossover above
+60. The indicator is mean-reverting around zero, so it is most useful
at extremes.
The canonical LazyBear defaults are
(channel_period = 10, average_period = 21, signal_period = 4); warmup is
channel_period + average_period + signal_period − 2.
Non-finite d (a zero-volatility seed where the absolute-deviation EMA
has not yet recorded any movement) collapses the channel index to zero.
§Example
use wickra_core::{Candle, Indicator, WaveTrend};
let mut indicator = WaveTrend::classic().unwrap();
let mut last = None;
for i in 0..80 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl WaveTrend
impl WaveTrend
Sourcepub fn new(
channel_period: usize,
average_period: usize,
signal_period: usize,
) -> Result<Self>
pub fn new( channel_period: usize, average_period: usize, signal_period: usize, ) -> Result<Self>
Construct a new Wave Trend Oscillator with explicit periods.
§Errors
Returns Error::PeriodZero if any period is 0.
Sourcepub fn classic() -> Result<Self>
pub fn classic() -> Result<Self>
LazyBear’s classic Wave Trend: (channel = 10, average = 21, signal = 4).
§Errors
None in practice — all periods are non-zero.
Sourcepub const fn periods(&self) -> (usize, usize, usize)
pub const fn periods(&self) -> (usize, usize, usize)
Configured (channel_period, average_period, signal_period).
Sourcepub const fn value(&self) -> Option<WaveTrendOutput>
pub const fn value(&self) -> Option<WaveTrendOutput>
Current value if available.
Trait Implementations§
Source§impl Indicator for WaveTrend
impl Indicator for WaveTrend
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = WaveTrendOutput
type Output = WaveTrendOutput
Source§fn update(&mut self, candle: Candle) -> Option<WaveTrendOutput>
fn update(&mut self, candle: Candle) -> Option<WaveTrendOutput>
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 WaveTrend
impl RefUnwindSafe for WaveTrend
impl Send for WaveTrend
impl Sync for WaveTrend
impl Unpin for WaveTrend
impl UnsafeUnpin for WaveTrend
impl UnwindSafe for WaveTrend
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