Indicator Math
A comprehensive Rust library for technical analysis indicators and automated market analysis. Perfect for trading systems, backtesting frameworks, and financial analysis applications.
Features
- Moving Averages: SMA, EMA, WMA, HMA (Hull), EHMA (Exponential Hull)
- Momentum Indicators: RSI (Relative Strength Index)
- Volatility Indicators: ATR (Average True Range), Bollinger Bands
- Trend Indicators: ADX (Average Directional Index), Choppiness Index
- Full Analysis Generator: Complete market analysis with SeriesCode lookup
Installation
Add this to your Cargo.toml:
[]
= "0.8.0"
Quick Start
Basic Indicators
use ;
// Create candle data
let candles = vec!;
// Calculate indicators
let ema_values = ema;
let rsi_values = rsi;
let atr_values = atr;
let bb = bollinger_bands;
let ci = choppiness_index;
let adx_result = adx;
// Access values
println!;
println!;
println!;
Full Analysis Generator (AnalysisGenerator)
The AnalysisGenerator provides comprehensive market analysis similar to the JavaScript clsAnalysisGenerator.js:
use ;
// Create candles
let candles = vec!;
// Configure options
let options = AnalysisOptions ;
// Create generator and analyze
let mut generator = new;
let analysis = generator.generate;
// Access analysis results
for item in analysis
// Get summary statistics
if let Some = generator.get_summary
SeriesCode Lookup
The library includes a built-in lookup table for StatusDesc to SeriesCode mapping:
use lookup_series_code;
// Lookup SeriesCode from StatusDesc
let code = lookup_series_code;
assert_eq!;
let code = lookup_series_code;
assert_eq!;
Legacy Analysis (EmaAnalysis)
For simpler EMA-based analysis:
use ;
let candles = vec!;
// Generate analysis
let analysis = generate_analysis_data;
// Get trading signals
let last_idx = analysis.len - 1;
let simple_action = get_action_by_simple;
let cut_action = get_action_by_cut_type;
println!; // "call", "put", or "hold"
println!;
Available Indicators
Moving Averages
| Function | Description |
|---|---|
sma(candles, period) |
Simple Moving Average |
ema(candles, period) |
Exponential Moving Average |
wma(candles, period) |
Weighted Moving Average |
hma(candles, period) |
Hull Moving Average |
ehma(candles, period) |
Exponential Hull Moving Average |
Momentum & Volatility
| Function | Description |
|---|---|
rsi(candles, period) |
Relative Strength Index (0-100) |
atr(candles, period) |
Average True Range |
bollinger_bands(candles, period) |
Bollinger Bands (Upper, Middle, Lower) |
Trend Indicators
| Function | Description |
|---|---|
choppiness_index(candles, period) |
Choppiness Index (0-100) |
adx(candles, period) |
Average Directional Index with +DI and -DI |
FullAnalysis Fields
The FullAnalysis struct provides comprehensive market data:
| Category | Fields |
|---|---|
| Basic | index, candle_time, open, high, low, close, color, pip_size |
| Short EMA | ema_short_value, ema_short_direction, ema_short_turn_type |
| Medium EMA | ema_medium_value, ema_medium_direction |
| Long EMA | ema_long_value, ema_long_direction |
| Relationships | ema_above, ema_long_above, macd_12, macd_23 |
| Convergence | ema_convergence_type, ema_long_convergence_type |
| Indicators | choppy_indicator, adx_value, rsi_value, atr |
| Bollinger | bb_upper, bb_middle, bb_lower, bb_position |
| Abnormal | is_abnormal_candle, is_abnormal_atr |
| Candle Body | upper_wick, body, lower_wick, *_percent |
| EMA Position | ema_cut_position, ema_cut_long_type, candles_since_ema_cut |
| Consecutive | up_con_medium_ema, down_con_medium_ema, up_con_long_ema, down_con_long_ema |
| Status | status_desc, series_code, is_mark, hint_status |
StatusDesc Format
The status_desc field follows this format: {EmaLongAbove}-{MediumDir}{LongDir}-{Color}-{ConvergenceType}
Examples:
L-DD-G-C= LongAbove, Down-Down directions, Green candle, ConvergenceM-UU-R-D= MediumAbove, Up-Up directions, Red candle, Divergence
License
MIT License - see LICENSE for details.