pub struct VolumeWeightedMacd { /* private fields */ }Expand description
Volume-Weighted MACD — the MACD oscillator computed from volume-weighted moving averages instead of plain EMAs.
macd = VWMA(close, fast) − VWMA(close, slow)
signal = EMA(macd, signal_period)
histogram = macd − signalStandard MacdIndicator smooths price with exponential
averages that ignore volume. The volume-weighted variant (Buff Dormeier and
others) replaces each average with a Vwma, so heavy-volume bars dominate
the trend estimate and the oscillator leans toward where real participation
occurred. Crossovers backed by volume therefore appear sooner and noise from
thin bars is damped. The signal line keeps a standard EMA, matching the
classic histogram construction.
fast must be strictly smaller than slow. The first output lands after
slow + signal − 1 inputs: slow to seed the slow VWMA, then signal − 1
more to seed the signal EMA. Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, VolumeWeightedMacd};
let mut indicator = VolumeWeightedMacd::new(12, 26, 9).unwrap();
let mut last = None;
for i in 0..80 {
let base = 100.0 + f64::from(i);
let c = Candle::new(base, base + 1.0, base - 1.0, base + 0.5, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl VolumeWeightedMacd
impl VolumeWeightedMacd
Sourcepub fn new(fast: usize, slow: usize, signal: usize) -> Result<Self>
pub fn new(fast: usize, slow: usize, signal: usize) -> Result<Self>
Construct a volume-weighted MACD with the given periods.
§Errors
Returns Error::PeriodZero if any period is zero, and
Error::InvalidPeriod if fast >= slow.
Sourcepub const fn periods(&self) -> (usize, usize, usize)
pub const fn periods(&self) -> (usize, usize, usize)
Configured periods as (fast, slow, signal).
Sourcepub const fn value(&self) -> Option<VolumeWeightedMacdOutput>
pub const fn value(&self) -> Option<VolumeWeightedMacdOutput>
Most recent fully-computed output if available.
Trait Implementations§
Source§impl Clone for VolumeWeightedMacd
impl Clone for VolumeWeightedMacd
Source§fn clone(&self) -> VolumeWeightedMacd
fn clone(&self) -> VolumeWeightedMacd
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VolumeWeightedMacd
impl Debug for VolumeWeightedMacd
Source§impl Indicator for VolumeWeightedMacd
impl Indicator for VolumeWeightedMacd
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = VolumeWeightedMacdOutput
type Output = VolumeWeightedMacdOutput
Source§fn update(&mut self, candle: Candle) -> Option<VolumeWeightedMacdOutput>
fn update(&mut self, candle: Candle) -> Option<VolumeWeightedMacdOutput>
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 VolumeWeightedMacd
impl RefUnwindSafe for VolumeWeightedMacd
impl Send for VolumeWeightedMacd
impl Sync for VolumeWeightedMacd
impl Unpin for VolumeWeightedMacd
impl UnsafeUnpin for VolumeWeightedMacd
impl UnwindSafe for VolumeWeightedMacd
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