pub struct CandleVolume { /* private fields */ }Expand description
CandleVolume — the candlestick analogue of Equivolume:
each bar’s body (close − open) paired with a width proportional to its
volume relative to the recent average.
body = close − open (signed; + bullish, − bearish)
width = volume / SMA(volume, period) (1.0 = average volume)Where Equivolume uses the high-low range for the box height, CandleVolume uses the candlestick body, preserving direction: a wide bullish body (long up candle on heavy volume) is strong demand, a wide bearish body strong supply, and a narrow body on heavy volume (wide but short) is churn. The signed body plus the normalised width capture both the move’s direction and the participation behind it.
The first value lands after period inputs (to seed the volume average). Each
update is O(1).
§Example
use wickra_core::{Candle, Indicator, CandleVolume};
let mut indicator = CandleVolume::new(14).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let c = Candle::new(base, base + 1.0, base - 1.0, base + 0.5, 1_000.0 + f64::from(i), 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl CandleVolume
impl CandleVolume
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a CandleVolume with the given volume-averaging period.
§Errors
Returns Error::PeriodZero if period == 0.
Sourcepub const fn value(&self) -> Option<CandleVolumeOutput>
pub const fn value(&self) -> Option<CandleVolumeOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for CandleVolume
impl Clone for CandleVolume
Source§fn clone(&self) -> CandleVolume
fn clone(&self) -> CandleVolume
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 CandleVolume
impl Debug for CandleVolume
Source§impl Indicator for CandleVolume
impl Indicator for CandleVolume
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = CandleVolumeOutput
type Output = CandleVolumeOutput
Source§fn update(&mut self, candle: Candle) -> Option<CandleVolumeOutput>
fn update(&mut self, candle: Candle) -> Option<CandleVolumeOutput>
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 CandleVolume
impl RefUnwindSafe for CandleVolume
impl Send for CandleVolume
impl Sync for CandleVolume
impl Unpin for CandleVolume
impl UnsafeUnpin for CandleVolume
impl UnwindSafe for CandleVolume
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