Skip to main content

Atr

Struct Atr 

Source
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§

Source§

impl<const N: usize> Atr<N>

Source

pub fn new() -> Self

Construct a new ATR over a Wilder period of N.

Source

pub const fn value(&self) -> Option<f64>

Current value if seeded.

Trait Implementations§

Source§

impl<const N: usize> Clone for Atr<N>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Atr<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Atr<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Indicator for Atr<N>

Source§

type Input = Candle

Type of one input data point (f64 for a price, Candle for an OHLC bar).
Source§

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)

Reset all internal state, leaving the indicator equivalent to a freshly constructed instance with the same parameters.
Source§

fn warmup_period(&self) -> usize

Number of inputs required before the first non-None output.
Source§

fn is_ready(&self) -> bool

Whether the indicator has produced at least one value since construction or the last reset.
Source§

fn name(&self) -> &'static str

Stable, human-readable indicator name.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.