pub struct VolumeWeightedSr { /* private fields */ }Expand description
Volume-Weighted Support/Resistance — a band whose edges are the volume-weighted average of the recent highs (resistance) and lows (support), so the levels gravitate toward the prices where trading actually happened.
support = Σ(low_i · volume_i) / Σ volume_i over the window
resistance = Σ(high_i · volume_i) / Σ volume_i over the windowPlain high/low channels (e.g. Donchian) weight every bar
equally, so a thin spike sets the boundary. Volume-weighting pulls the support
and resistance toward the highs and lows that carried real volume — the prices
the market agreed mattered — giving levels that tend to hold better. The
distance between the two is a volume-aware range estimate. If the window’s
volume is all zero the band falls back to the equal-weighted average high and
low.
The first value lands after period inputs; each update is O(1).
§Example
use wickra_core::{Candle, Indicator, VolumeWeightedSr};
let mut indicator = VolumeWeightedSr::new(20).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + (f64::from(i) * 0.3).sin() * 5.0;
let c = Candle::new(base, base + 2.0, base - 2.0, base, 1_000.0 + f64::from(i), 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl VolumeWeightedSr
impl VolumeWeightedSr
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a volume-weighted S/R band over period bars.
§Errors
Returns Error::PeriodZero if period == 0.
Sourcepub const fn value(&self) -> Option<VolumeWeightedSrOutput>
pub const fn value(&self) -> Option<VolumeWeightedSrOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for VolumeWeightedSr
impl Clone for VolumeWeightedSr
Source§fn clone(&self) -> VolumeWeightedSr
fn clone(&self) -> VolumeWeightedSr
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 VolumeWeightedSr
impl Debug for VolumeWeightedSr
Source§impl Indicator for VolumeWeightedSr
impl Indicator for VolumeWeightedSr
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = VolumeWeightedSrOutput
type Output = VolumeWeightedSrOutput
Source§fn update(&mut self, candle: Candle) -> Option<VolumeWeightedSrOutput>
fn update(&mut self, candle: Candle) -> Option<VolumeWeightedSrOutput>
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 VolumeWeightedSr
impl RefUnwindSafe for VolumeWeightedSr
impl Send for VolumeWeightedSr
impl Sync for VolumeWeightedSr
impl Unpin for VolumeWeightedSr
impl UnsafeUnpin for VolumeWeightedSr
impl UnwindSafe for VolumeWeightedSr
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