pub struct TradeVolumeIndex { /* private fields */ }Expand description
Trade Volume Index — a cumulative line that adds volume while price ticks up and subtracts it while price ticks down, where “up” and “down” are decided by a minimum tick value rather than any change.
change = close − prev_close
if change > min_tick: direction = +1
if change < −min_tick: direction = −1
else: direction unchanged (price is "churning")
TVI_t = TVI_{t−1} + direction * volumeThe minimum tick value (MTV) is a dead-band: only moves larger than min_tick
flip the accumulation direction, so a price drifting within the spread keeps
adding volume in the last established direction instead of whipsawing. This is
the cumulative-volume analogue of Obv, but with a noise filter
and applied to close-to-close moves. Like all cumulative lines, only its slope
and divergences against price carry meaning — the absolute level is arbitrary.
The first candle seeds the reference close and emits nothing; thereafter each
bar emits the running total. Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, TradeVolumeIndex};
let mut indicator = TradeVolumeIndex::new(0.5).unwrap();
let mut last = None;
for i in 0..20 {
let close = 100.0 + f64::from(i);
let c = Candle::new(close, close + 0.5, close - 0.5, close, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl TradeVolumeIndex
impl TradeVolumeIndex
Trait Implementations§
Source§impl Clone for TradeVolumeIndex
impl Clone for TradeVolumeIndex
Source§fn clone(&self) -> TradeVolumeIndex
fn clone(&self) -> TradeVolumeIndex
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 TradeVolumeIndex
impl Debug for TradeVolumeIndex
Source§impl Indicator for TradeVolumeIndex
impl Indicator for TradeVolumeIndex
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
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 TradeVolumeIndex
impl RefUnwindSafe for TradeVolumeIndex
impl Send for TradeVolumeIndex
impl Sync for TradeVolumeIndex
impl Unpin for TradeVolumeIndex
impl UnsafeUnpin for TradeVolumeIndex
impl UnwindSafe for TradeVolumeIndex
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