Skip to content

Technical Indicators

Matchstick includes 15 technical indicators implemented in crates/indicators/.

Available indicators

#IndicatorTypeMulti-value
1SMASimple Moving AverageNo
2EMAExponential Moving AverageNo
3WMAWeighted Moving AverageNo
4VWMAVolume-Weighted Moving AverageNo
5RSIRelative Strength IndexNo
6MACDMoving Average Convergence DivergenceYes (macd, signal, histogram)
7Bollinger BandsVolatility bandsYes (upper, middle, lower)
8StochasticStochastic oscillatorYes (%K, %D)
9ATRAverage True RangeNo
10ADXAverage Directional IndexNo
11Williams %RWilliams Percent RangeNo
12CCICommodity Channel IndexNo
13OBVOn-Balance VolumeNo
14MFIMoney Flow IndexNo
15VWAPVolume-Weighted Average PriceNo

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 indicators
  • values: 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

Built for traders who value data provenance.