Struct ATR

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

Average True Range (ATR) Calculator

ATR measures market volatility by calculating the average of true ranges over a period. True Range is the greatest of:

  • Current High - Current Low
  • |Current High - Previous Close|
  • |Current Low - Previous Close|

Implementations§

Source§

impl ATR

Source

pub fn new(period: usize) -> Result<Self, ATRError>

Creates a new ATR calculator with the specified period

Source

pub fn update(&mut self, data: OHLCData) -> Option<ATRResult>

Updates ATR with OHLC data

Source

pub fn update_hlc( &mut self, high: f64, low: f64, close: f64, ) -> Option<ATRResult>

Updates ATR with separate high, low, close values

Source

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

Calculate with just closing price (simplified - less accurate)

Source

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

Returns the current ATR value

Source

pub fn result(&self) -> Option<ATRResult>

Returns the current ATR result with true range

Source

pub fn reset(&mut self)

Resets the calculator

Source

pub fn period(&self) -> usize

Get the period

Source

pub fn is_ready(&self) -> bool

Check if ATR is initialized

Source

pub fn calculate_batch( period: usize, data: &[OHLCData], ) -> Result<Vec<Option<ATRResult>>, ATRError>

Batch calculation for historical data

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.