pub struct TwiggsMoneyFlow { /* private fields */ }Expand description
Twiggs Money Flow — a refinement of Chaikin Money Flow that uses true range boundaries and Wilder (exponential) smoothing instead of a simple sum.
TRH = max(high, prev_close) (true high)
TRL = min(low, prev_close) (true low)
ad = volume * (2*close − TRH − TRL) / (TRH − TRL) (0 if TRH == TRL)
TMF = WilderEMA(ad, period) / WilderEMA(volume, period)Colin Twiggs’ money flow fixes two issues with Cmf: it replaces
the bar’s raw high/low with the true high/low (folding in the prior close so
gaps count), and it smooths the accumulated money flow and the volume with a
Wilder exponential average rather than a flat period-sum, so the oscillator
reacts faster and never jumps when a large bar drops out of a window. The
output is bounded in roughly [−1, +1]: positive means buying pressure
(closes biased toward the true high), negative means selling pressure.
The first candle seeds the reference close; the next period bars seed both
Wilder averages, so the first value lands after period + 1 inputs. A stretch
of zero volume makes the denominator average 0, in which case the oscillator
reports 0 rather than 0 / 0. Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, TwiggsMoneyFlow};
let mut indicator = TwiggsMoneyFlow::new(21).unwrap();
let mut last = None;
for i in 0..60 {
let base = 100.0 + (f64::from(i) * 0.2).sin() * 5.0;
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 TwiggsMoneyFlow
impl TwiggsMoneyFlow
Trait Implementations§
Source§impl Clone for TwiggsMoneyFlow
impl Clone for TwiggsMoneyFlow
Source§fn clone(&self) -> TwiggsMoneyFlow
fn clone(&self) -> TwiggsMoneyFlow
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 TwiggsMoneyFlow
impl Debug for TwiggsMoneyFlow
Source§impl Indicator for TwiggsMoneyFlow
impl Indicator for TwiggsMoneyFlow
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 TwiggsMoneyFlow
impl RefUnwindSafe for TwiggsMoneyFlow
impl Send for TwiggsMoneyFlow
impl Sync for TwiggsMoneyFlow
impl Unpin for TwiggsMoneyFlow
impl UnsafeUnpin for TwiggsMoneyFlow
impl UnwindSafe for TwiggsMoneyFlow
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