pub struct Atr<const N: usize> { /* private fields */ }Expand description
Average True Range over a Wilder period N.
Seeds with the mean of the first N true ranges, then applies Wilder
smoothing avg.mul_add(N - 1, tr) / N, identical to wickra_core::Atr. The
first value appears after N candles. Input is a Candle; only high, low
and the previous close are read.
§Example
use wickra_embed_core::{Atr, Candle, Indicator};
let mut atr = Atr::<5>::new();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let c = Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 10.0, i64::from(i));
last = atr.update(c);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl<const N: usize> Indicator for Atr<N>
impl<const N: usize> Indicator for Atr<N>
Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> Option<f64>
Feed one new data point in and return the freshly computed value, or
None while still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output.Auto Trait Implementations§
impl<const N: usize> Freeze for Atr<N>
impl<const N: usize> RefUnwindSafe for Atr<N>
impl<const N: usize> Send for Atr<N>
impl<const N: usize> Sync for Atr<N>
impl<const N: usize> Unpin for Atr<N>
impl<const N: usize> UnsafeUnpin for Atr<N>
impl<const N: usize> UnwindSafe for Atr<N>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more