pub struct TdMovingAverage { /* private fields */ }Expand description
Tom DeMark TD Moving Averages — a two-line trend ribbon (ST1 fast, ST2 slow) computed on the median price, whose relationship defines the trend.
price = (high + low) / 2 (median price)
st1 = SMA(price, period_st1) (fast / "Sequential Trend 1")
st2 = SMA(price, period_st2) (slow / "Sequential Trend 2")DeMark’s moving-average pair frames the trend objectively: when st1 is above
st2 the trend is up, below it down, and the cross marks the change. Using the
median price rather than the close de-emphasises closing noise. This is a
streaming dual-SMA implementation of the ST1/ST2 ribbon; read the lines and
their crossover exactly as a fast/slow moving-average system.
period_st1 must be strictly smaller than period_st2. The first value lands
once the slow average is seeded (period_st2 inputs). Each update is O(1).
§Example
use wickra_core::{Candle, Indicator, TdMovingAverage};
let mut indicator = TdMovingAverage::new(5, 13).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, 1_000.0, 0).unwrap();
last = indicator.update(c);
}
assert!(last.is_some());Implementations§
Source§impl TdMovingAverage
impl TdMovingAverage
Sourcepub fn new(period_st1: usize, period_st2: usize) -> Result<Self>
pub fn new(period_st1: usize, period_st2: usize) -> Result<Self>
Construct TD Moving Averages with the given fast and slow periods.
§Errors
Returns Error::PeriodZero if either period is 0, and
Error::InvalidPeriod if period_st1 >= period_st2.
Sourcepub const fn value(&self) -> Option<TdMovingAverageOutput>
pub const fn value(&self) -> Option<TdMovingAverageOutput>
Current value if available.
Trait Implementations§
Source§impl Clone for TdMovingAverage
impl Clone for TdMovingAverage
Source§fn clone(&self) -> TdMovingAverage
fn clone(&self) -> TdMovingAverage
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 TdMovingAverage
impl Debug for TdMovingAverage
Source§impl Indicator for TdMovingAverage
impl Indicator for TdMovingAverage
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = TdMovingAverageOutput
type Output = TdMovingAverageOutput
Source§fn update(&mut self, candle: Candle) -> Option<TdMovingAverageOutput>
fn update(&mut self, candle: Candle) -> Option<TdMovingAverageOutput>
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 TdMovingAverage
impl RefUnwindSafe for TdMovingAverage
impl Send for TdMovingAverage
impl Sync for TdMovingAverage
impl Unpin for TdMovingAverage
impl UnsafeUnpin for TdMovingAverage
impl UnwindSafe for TdMovingAverage
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