Expand description
Standalone batch indicator functions and incremental structs.
Ported from the original indicators crate lib. These work on slices
(batch mode) or as incremental O(1)-per-tick structs.
§Incremental warm-up contract
Every Incremental* struct has the same update shape: it returns
Option<T>, where None means “no value is defined yet”. Structs whose
maths seeds from the first tick (EMA, ATR, MACD) return Some from the
first call; the others return None until their warm-up completes:
| Struct | update returns | First Some |
|---|---|---|
IncrementalEma | Option<f64> | first tick (seeds from it) |
IncrementalAtr | Option<f64> | first tick (TR = high − low) |
IncrementalRsi | Option<f64> | second tick (needs a prior price) |
IncrementalMacd | Option<(f64, f64, f64)> | first tick (all EMAs seed from it) |
IncrementalBollinger | Option<BollingerBandsValue> | after period ticks |
EMA / ATR | () — read via value() / is_ready() | after period ticks (SMA seed) |
Early EMA/MACD values are mathematically defined but still converging toward the batch equivalents (which warm up with an SMA seed or leading NaN); gate on your own bar count if you need fully-converged values.
None of these structs validate their inputs: feeding NaN poisons the internal state (NaN propagates through every subsequent value) without panicking. Filter non-finite ticks upstream.
Structs§
- ATR
- Incremental Wilder ATR.
- Bollinger
Bands Value - Per-tick Bollinger Bands output (see
IncrementalBollinger). - EMA
- Incremental EMA — O(1) update, SMA warm-up.
- Incremental
Atr - Incremental ATR — O(1) per-tick true-range EMA.
- Incremental
Bollinger - Incremental Bollinger Bands — per-tick bands over a rolling window.
- Incremental
Ema - Incremental EMA — O(1) update per tick that returns the new value each call.
- Incremental
Macd - Incremental MACD — O(1) per-tick MACD line, signal, and histogram.
- Incremental
Rsi - Incremental RSI — O(1) per-tick, EMA-smoothed gains/losses.
- Indicator
Calculator - Multi-period indicator calculator (batch mode).
- Strategy
Indicators - Bundle of per-strategy indicator series.
Functions§
- atr
- Average True Range (EMA-smoothed).
- ema
- Exponential Moving Average over a price slice.
Returns a Vec of the same length; leading values are
NaNuntil warm-up. - ema_
nan_ aware - EMA that handles leading NaN values, matching Python’s
ewm(adjust=False)behaviour. - macd
- MACD — returns (macd_line, signal_line, histogram).
- rsi
- Relative Strength Index.
- sma
- Simple Moving Average over a price slice.
- true_
range - True Range = max(H-L, |H-prevC|, |L-prevC|).