Weighted Moving Average (WMA)
period = 30 Overview
The Weighted Moving Average (WMA) applies linearly increasing weights to price data across the lookback window, assigning the highest weight to the most recent price and progressively smaller weights to older prices. Each position in the period receives a weight equal to its distance from the start, so in a 30-period WMA, today gets weight 30, yesterday gets 29, and the oldest bar gets weight 1. These weights sum to n(n+1)/2, providing the divisor that normalizes the weighted sum into the final average. This linear weighting scheme makes WMA significantly more responsive to recent price changes than Simple Moving Average while maintaining greater smoothness than pure momentum indicators. The graduated weighting naturally emphasizes current market conditions without completely discarding historical context, striking a practical balance for trend identification. Traders favor WMA when they need quicker reaction to price shifts than SMA provides but want to avoid the exponential weighting assumptions of EMA. The default 30-period setting produces smooth trend lines suitable for intermediate term analysis, with VectorTA optimizations delivering high performance through SIMD acceleration and efficient streaming updates.
Formula: WMAt = \dfrac{\sum_{i=1}^{n} i\,x_{t-n+i}}{n(n+1)/2}, where n = period and the most recent bar has weight n. Default (VectorTA): period = 30.
See also
- Simple Moving Average (SMA) — equal weights baseline.
- Exponential Moving Average (EMA) — exponential weighting.
- Hull Moving Average (HMA) — WMA-based smoothing/acceleration.
- Symmetric (Triangular) WMA (SWMA) — symmetric weights.
Interpretation & Use
- Trend filter: Rising WMA suggests bullish bias; falling WMA suggests bearish bias.
- Crossovers: Price/WMA cross or multi-WMA stacks can signal momentum shifts.
- Lag vs responsiveness: Larger period smooths more but lags; smaller reacts faster with more noise.
- Warmup: First first + period − 1 indices are NaN until the window is fully seeded.
Implementation Examples
Compute WMA from a slice or candles:
use vectorta::indicators::wma::{wma, WmaInput, WmaParams};
use vectorta::utilities::data_loader::{Candles, read_candles_from_csv};
// Using with a price slice
let prices = vec![100.0, 102.0, 101.5, 103.0, 105.0, 104.5];
let params = WmaParams { period: Some(30) };
let input = WmaInput::from_slice(&prices, params);
let out = wma(&input)?;
// Using with Candles (default source="close", period=30)
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let input = WmaInput::from_candles(&candles, "close", WmaParams::default());
let out = wma(&input)?;
for v in out.values { println!("WMA: {}", v); } API Reference
Input Methods ▼
// From price slice
WmaInput::from_slice(&[f64], WmaParams) -> WmaInput
// From candles with custom source
WmaInput::from_candles(&Candles, &str, WmaParams) -> WmaInput
// With defaults (source="close", period=30)
WmaInput::with_default_candles(&Candles) -> WmaInput Parameters Structure ▼
pub struct WmaParams {
pub period: Option<usize>, // Default: 30
} Output Structure ▼
pub struct WmaOutput {
pub values: Vec<f64>, // WMA values
} Validation, Warmup & Errors ▼
period > 0andperiod ≤ data.len(); elseWmaError::InvalidPeriod.- All-NaN input →
WmaError::AllValuesNaN. - Require at least
periodvalid points after first finite; elseWmaError::NotEnoughValidData. - Warmup: indices
[0 .. first+period-2]areNaN; first valid output atfirst+period-1.
Export Code
use vectorta::indicators::wma;
// Calculate WMA with custom parameters
let result = wma(&data, 30);
// Or using the builder pattern
let result = indicators::wma::new()
.period(30)
.calculate(&data);This code snippet shows how to use the WMA indicator with your current parameter settings.
Performance Analysis
Across sizes, Rust CPU runs about 1.00× faster than Tulip C in this benchmark.
AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU) | Benchmarks: 2026-01-05
Related Indicators
Arnaud Legoux Moving Average
Moving average indicator
Compound Ratio Moving Average (CoRa Wave)
Moving average indicator
Centered Weighted Moving Average
Moving average indicator
Double Exponential Moving Average
Moving average indicator
Ehlers Distance Coefficient Filter
Moving average indicator
Ehlers Error-Correcting EMA (ECEMA)
Moving average indicator