Struct ta::indicators::TrueRange[][src]

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

The range of a day’s trading is simply high - low. The true range extends it to yesterday’s closing price if it was outside of today’s range.

The true range is the largest of one the following:

  • Most recent period’s high minus the most recent period’s low
  • Absolute value of the most recent period’s high minus the previous close
  • Absolute value of the most recent period’s low minus the previous close

Formula

TR = max[(high - low), abs(high - closeprev), abs(low - closeprev)]

Example

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

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

fn main() {
    let data = vec![
        // open, high, low, close, tr
        (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.9),  // tr = high - prev_close = 10.4 - 9.5 = 0.9
        (10.1  , 10.7, 9.4, 9.7  , 1.3),  // tr = high - low = 10.7 - 9.4 = 1.3
        (9.1   , 9.2 , 8.1, 8.4  , 1.6),  // tr = prev_close - low = 9.7 - 8.1 = 1.6
    ];
    let mut indicator = TrueRange::new();

    for (open, high, low, close, tr) 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), tr);
    }
}

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.