Expand description
§Average True Range (ATR)
Wilder ATR of high / low / close:
TR[i] = max( high−low, |high−close_prev|, |low−close_prev| )
ATR[i] = Wilder smooth of TR over `period`
(seed = SMA of first `period` true ranges)Default pack: period 14 (AtrParams::period_14).
Keltner channels reuse this definition internally for their ATR leg.
§Trading perspective
| Use | Habit |
|---|---|
| Volatility level | Wide ATR → large stops / size down |
| Breakout filters | Move in ATR units |
| Keltner width | mult * ATR around EMA |
§Engineering perspective
AtrParams → ValidatedAtr / atr → AtrState → atr_solution.
First ATR at index period − 1 when bar 0 has TR = high−low only (no prior close).
§Word problem
Constant 2-point range bars, no gaps. What is ATR(14) after warm-up?
≈ 2.0.
use finance_solution::stocks::ta::{atr, AtrParams};
let n = 30usize;
let high: Vec<_> = (0..n).map(|_| 102.0).collect();
let low: Vec<_> = (0..n).map(|_| 100.0).collect();
let close: Vec<_> = (0..n).map(|_| 101.0).collect();
let s = atr(&high, &low, &close, AtrParams::period_14()).unwrap();
assert!((s.last().unwrap() - 2.0).abs() < 1e-9);Structs§
- AtrParams
- ATR lookback pack (Wilder).
- AtrSeries
- AtrSolution
- AtrState
- Incremental Wilder ATR.
- Validated
Atr - Validated ATR config.
Functions§
- atr
- atr_
solution - Examples