A collection of technical analysis indicators for trading, written in Rust. Each indicator is gated behind a Cargo feature flag so you only compile what you need.
| Indicator | Feature | Description |
|---|---|---|
| Median Price | median_price |
(high + low) / 2 |
| True Range | tr |
Volatility measure: max(H-L, |H-pC|, |L-pC|) |
| Simple Moving Average | sma |
Arithmetic mean over a sliding window |
| Smoothed Moving Average | smma |
Modified moving average with smoother response |
| Exponential Moving Average | ema |
Exponentially weighted moving average |
| Running Moving Average | rma |
Wilder's smoothing (α = 1/N) |
| Weighted Moving Average | wma |
Linearly weighted moving average |
| Average True Range | atr |
ATR with 5 smoothing engines (SMA, SMMA, EMA, RMA, WMA) |
| MACD | macd |
Moving Average Convergence Divergence (histogram, signal, MACD line) |
| Supertrend | supertrend |
Trend-following indicator with upper/lower bands |
| Williams Fractals | wf |
Local price extreme points for support/resistance |
This crate uses Cargo feature flags to enable indicators individually:
[dependencies]
qtrade-indicators = { version = "0.1", features = ["sma", "ema", "macd"] }Some features automatically enable others:
atrenablestr,sma,smma,ema,rma,wmamacdenablesema
For development and testing, enable all features:
[dependencies]
qtrade-indicators = { version = "0.1", features = ["dev"] }Add the crate to your Cargo.toml:
[dependencies]
qtrade-indicators = { version = "0.1", features = ["sma"] }use qtrade_indicators::simple_moving_average::{SettingSma, calculate_sma};
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let setting = SettingSma { period: 3 };
let sma = calculate_sma(&data, &setting).unwrap();
// sma = [0.0, 0.0, 2.0, 3.0, 4.0]use qtrade_indicators::moving_average_convergence_divergence::{
SettingMacd, calculate_macd,
};
let data: Vec<f64> = (10..31).map(|i| i as f64).collect();
let setting = SettingMacd {
fast_length: 3,
slow_length: 5,
signal_smooth: 3,
};
let macd = calculate_macd(&data, &setting).unwrap();use qtrade_indicators::supertrend::{SettingSupertrend, calculate_supertrend};
let close = vec![10.0, 11.0, 12.0, 9.0, 8.0, 13.0];
let median = vec![10.0, 10.5, 11.5, 9.5, 8.5, 12.5];
let atr = vec![1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
let setting = SettingSupertrend { factor: 2.0 };
let st = calculate_supertrend(&close, &median, &atr, &setting).unwrap();
println!("Trend: {:?}", st[0].trend); // UpFull API documentation is available on docs.rs.
Rust 1.85 or later (Rust 2024 edition).
Licensed under the Apache License, Version 2.0. See LICENSE for details.