pub struct MacdExt { /* private fields */ }Expand description
MACD Extended (MACDEXT): MACD with an independently selectable
MaType for each of the fast, slow and signal lines.
Classic MacdIndicator hard-wires the exponential
moving average everywhere; MACDEXT lets each line use any period-only
moving average. The MACD line is fast_ma(price) − slow_ma(price), the signal
line is signal_ma(macd), and the histogram is macd − signal. The first
full MacdOutput is emitted once the slow and signal averages are both warm.
§Example
use wickra_core::{Indicator, MacdExt, MaType};
let mut indicator =
MacdExt::new(12, MaType::Ema, 26, MaType::Ema, 9, MaType::Sma).unwrap();
let mut last = None;
for i in 0..120 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl MacdExt
impl MacdExt
Sourcepub fn new(
fast: usize,
fast_type: MaType,
slow: usize,
slow_type: MaType,
signal: usize,
signal_type: MaType,
) -> Result<Self>
pub fn new( fast: usize, fast_type: MaType, slow: usize, slow_type: MaType, signal: usize, signal_type: MaType, ) -> Result<Self>
Construct a MACDEXT with per-line periods and moving-average types.
§Errors
Returns Error::PeriodZero if any period is zero and
Error::InvalidPeriod if fast >= slow, propagating any moving-average
construction error.
Trait Implementations§
Source§impl Indicator for MacdExt
impl Indicator for MacdExt
Source§type Output = MacdOutput
type Output = MacdOutput
Type of one output value.
Source§fn update(&mut self, value: f64) -> Option<MacdOutput>
fn update(&mut self, value: f64) -> Option<MacdOutput>
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 MacdExt
impl RefUnwindSafe for MacdExt
impl Send for MacdExt
impl Sync for MacdExt
impl Unpin for MacdExt
impl UnsafeUnpin for MacdExt
impl UnwindSafe for MacdExt
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