Expand description
Tier 1 indicators with streaming and batch APIs.
§Examples
Compute several indicators over a generated candle series:
use mantis_ta::indicators::{
BollingerBands, Indicator, MACD, OBV, PivotPoints, RSI, SMA, Stochastic, VolumeSMA, ATR, EMA,
};
use mantis_ta::types::Candle;
// Build a small candle series (60 bars) for the examples.
let candles: Vec<Candle> = (0..60)
.map(|i| Candle {
timestamp: i,
open: 100.0 + i as f64 * 0.1,
high: 100.2 + i as f64 * 0.1,
low: 99.8 + i as f64 * 0.1,
close:100.1 + i as f64 * 0.1,
volume: 1_000.0 + i as f64,
})
.collect();
// Batch calculations (Vec<Option<_>> aligned to input)
let sma = SMA::new(20).calculate(&candles);
let ema = EMA::new(20).calculate(&candles);
let macd = MACD::new(12, 26, 9).calculate(&candles);
let rsi = RSI::new(14).calculate(&candles);
let stoch = Stochastic::new(14, 3).calculate(&candles);
let bb = BollingerBands::new(20, 2.0).calculate(&candles);
let atr = ATR::new(14).calculate(&candles);
let vol_sma = VolumeSMA::new(20).calculate(&candles);
let obv = OBV::new().calculate(&candles);
let pivot = PivotPoints::new().calculate(&candles);
// All indicators produce `None` until their warmup is reached.
assert!(sma.iter().take(19).all(|v| v.is_none()));
assert!(ema.iter().take(19).all(|v| v.is_none()));
assert!(rsi.iter().take(13).all(|v| v.is_none()));
// Stochastic warmup = k + d - 1 (14 + 3 - 1 = 16)
assert!(stoch.iter().take(15).all(|v| v.is_none()));
assert!(stoch[15].is_some());
assert!(bb.iter().take(19).all(|v| v.is_none()));
assert!(atr.iter().take(13).all(|v| v.is_none()));
assert!(macd.iter().all(|v| v.is_none()) || macd.iter().any(|v| v.is_some()));
assert!(pivot.iter().all(|v| v.is_some()));
assert!(obv.iter().all(|v| v.is_some()));
assert!(vol_sma.iter().take(19).all(|v| v.is_none()));
// Streaming example: re-use the same indicator instance per-bar
let mut rsi_stream = RSI::new(14);
for c in &candles {
let _ = rsi_stream.next(c);
}Re-exports§
pub use momentum::CCI;pub use momentum::ROC;pub use momentum::RSI;pub use momentum::Stochastic;pub use momentum::WilliamsR;pub use obv::OBV;pub use support_resistance::PivotPoints;pub use trend::ADX;pub use trend::DEMA;pub use trend::EMA;pub use trend::MACD;pub use trend::SMA;pub use trend::TEMA;pub use trend::WMA;pub use volatility::ATR;pub use volatility::BollingerBands;pub use volatility::StdDev;pub use volume::VolumeSMA;pub use crate::types::BollingerOutput;pub use crate::types::MacdOutput;pub use crate::types::PivotOutput;pub use crate::types::StochasticOutput;
Modules§
Traits§
- Incremental
Indicator - Extension of
Indicatorthat supports state snapshot/restore. - Indicator
- Core interface for all streaming technical indicators.