Module main

Source
Expand description

§Average True Range (ATR) Module

This module implements a simplified Average True Range (ATR) indicator. In this version, the true range is calculated as the absolute difference between the current closing price and the previous closing price. (Note that the full ATR calculation typically uses the high, low, and previous close values, but this simplified version uses only the close values.)

The ATR is computed as the average of the true range over a specified period.

§Examples

use indexes_rs::v1::atr::main::ATR;

// Create an ATR indicator with a period of 14
let mut atr = ATR::new(14);

// Feed a series of closing prices
let prices = vec![100.0, 101.0, 100.5, 102.0, 101.5, 102.5, 103.0, 102.0, 101.0, 100.0,
                  100.5, 101.0, 102.0, 101.5, 102.5];

for price in prices {
    if let Some(atr_value) = atr.calculate(price) {
        println!("ATR: {:.2}", atr_value);
    }
}

Structs§

ATR
A simplified Average True Range (ATR) indicator.