Struct ATR

Source
pub struct ATR { /* private fields */ }
Expand description

A simplified Average True Range (ATR) indicator.

This ATR calculates the true range as the absolute difference between the current closing price and the previous closing price. It then computes the ATR as the average of these true ranges over a specified period.

Implementations§

Source§

impl ATR

Source

pub fn new(period: usize) -> Self

Creates a new ATR indicator with the specified period.

§Arguments
  • period - The number of periods over which to calculate the ATR.
§Example
use indexes_rs::v1::atr::main::ATR;

let atr = ATR::new(14);
Source

pub fn calculate(&mut self, close: f64) -> Option<f64>

Calculates the current ATR value using the latest closing price.

The true range is computed as the absolute difference between the current closing price and the previous closing price. This true range is stored in a sliding window; once the window contains period values, the ATR is returned as their average.

§Arguments
  • close - The latest closing price.
§Returns
  • Some(f64) containing the ATR value if enough data is available.
  • None if there aren’t enough values yet.

Auto Trait Implementations§

§

impl Freeze for ATR

§

impl RefUnwindSafe for ATR

§

impl Send for ATR

§

impl Sync for ATR

§

impl Unpin for ATR

§

impl UnwindSafe for ATR

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.