Struct ta::indicators::AverageTrueRange[][src]

pub struct AverageTrueRange { /* fields omitted */ }
Expand description

Average true range (ATR).

A technical analysis volatility indicator, originally developed by J. Welles Wilder. The average true range is an N-day smoothed moving average of the true range values. This implementation uses exponential moving average.

Formula

ATR(period)t = EMA(period) of TRt

Where:

Parameters

  • period - smoothing period of EMA (integer greater than 0)

Example

extern crate ta;
#[macro_use] extern crate assert_approx_eq;

use ta::{Next, DataItem};
use ta::indicators::AverageTrueRange;

fn main() {
    let data = vec![
        // open, high, low, close, atr
        (9.7   , 10.0, 9.0, 9.5  , 1.0),    // tr = high - low = 10.0 - 9.0 = 1.0
        (9.9   , 10.4, 9.8, 10.2 , 0.95),   // tr = high - prev_close = 10.4 - 9.5 = 0.9
        (10.1  , 10.7, 9.4, 9.7  , 1.125),  // tr = high - low = 10.7 - 9.4 = 1.3
        (9.1   , 9.2 , 8.1, 8.4  , 1.3625), // tr = prev_close - low = 9.7 - 8.1 = 1.6
    ];
    let mut indicator = AverageTrueRange::new(3).unwrap();

    for (open, high, low, close, atr) in data {
        let di = DataItem::builder()
            .high(high)
            .low(low)
            .close(close)
            .open(open)
            .volume(1000.0)
            .build().unwrap();
        assert_approx_eq!(indicator.next(&di), atr);
    }
}

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.