Technical Indicators
Matchstick includes 15 technical indicators implemented in crates/indicators/.
Available indicators
| # | Indicator | Type | Multi-value |
|---|---|---|---|
| 1 | SMA | Simple Moving Average | No |
| 2 | EMA | Exponential Moving Average | No |
| 3 | WMA | Weighted Moving Average | No |
| 4 | VWMA | Volume-Weighted Moving Average | No |
| 5 | RSI | Relative Strength Index | No |
| 6 | MACD | Moving Average Convergence Divergence | Yes (macd, signal, histogram) |
| 7 | Bollinger Bands | Volatility bands | Yes (upper, middle, lower) |
| 8 | Stochastic | Stochastic oscillator | Yes (%K, %D) |
| 9 | ATR | Average True Range | No |
| 10 | ADX | Average Directional Index | No |
| 11 | Williams %R | Williams Percent Range | No |
| 12 | CCI | Commodity Channel Index | No |
| 13 | OBV | On-Balance Volume | No |
| 14 | MFI | Money Flow Index | No |
| 15 | VWAP | Volume-Weighted Average Price | No |
API
IndicatorRequest
Create a request specifying what to calculate:
rust
use indicators::{IndicatorEngine, IndicatorRequest};
let mut engine = IndicatorEngine::new();
// Simple request
let request = IndicatorRequest::sma("AAPL".to_string(), 20);
// Calculate against OHLCV data
let result = engine.calculate(&request, &bars).unwrap();
println!("SMA(20) = {:?}", result.value);IndicatorResult
Results contain:
value: Option<f64>- Single value for simple indicatorsvalues: HashMap<String, f64>- Named values for multi-value indicators (MACD, Bollinger, Stochastic)metadata: HashMap<String, String>- Additional info
Multi-value example
rust
let request = IndicatorRequest::macd("AAPL".to_string());
let result = engine.calculate(&request, &bars).unwrap();
// Access individual components
let macd_line = result.values.get("macd");
let signal_line = result.values.get("signal");
let histogram = result.values.get("histogram");Caching
The IndicatorEngine caches results with a 5-minute TTL. Cache keys are based on indicator type, symbol, period, and a hash of the input data. Call engine.clear_expired_cache() to manually evict stale entries.
Implementation notes
- All calculations use simple Rust loops (no external math libraries)
- RSI and ADX use Wilder's smoothing method
- EMA supports custom smoothing factor via parameters
- Input validation checks OHLCV bar integrity (high >= low, etc.)
- 25 inline tests verify calculation correctness