kestrel-chartkitv0.33.0

← All examples

atr

Average True Range

atr

examples/site_showcase.rs
// Average True Range (true-range average: build_typed accepts smoothing=rma|sma|ema|wma, build_checked the same as smoothing=0|1|2|3; rma is the default and the signal line stays Wilder-smoothed)
// Defaults of "atr" (see the indicator reference)
let params = HashMap::from([
    ("atr_len".to_string(), 14.0),
    ("sig_len".to_string(), 20.0),
    ("smoothing".to_string(), 0.0),
]);
let mut indicator = build_checked("atr", &params)?;

for bar in &bars {
    if let Some(output) = indicator.on_bar(bar) {
        // output.value, output.extra[...], indicator.alerts()
    }
}
Average True Range (true-range average: build_typed accepts smoothing=rma|sma|ema|wma, build_checked the same as smoothing=0|1|2|3; rma is the default and the signal line stays Wilder-smoothed). Default parameters on synthetic 4-hour bars of a fictitious CASOON share (invented prices), the last 150 bars; 34 alerts in view, the latest as markers.Average True Range (true-range average: build_typed accepts smoothing=rma|sma|ema|wma, build_checked the same as smoothing=0|1|2|3; rma is the default and the signal line stays Wilder-smoothed). Default parameters on synthetic 4-hour bars of a fictitious CASOON share (invented prices), the last 150 bars; 34 alerts in view, the latest as markers.
  • Volatility and trend strength
  • unit: Ratio