Moving Average

A moving average smooths price data by calculating the average price over a specific period, creating a single flowing line that helps filter out short-term fluctuations and highlight longer-term trends. Different types of moving averages weight historical prices differently, with exponential and smoothed variants giving more weight to recent prices.

Moving averages were among the first technical indicators developed and remain one of the most widely used tools in technical analysis. They form the foundation for many other indicators and trading strategies.

What It Measures

Moving averages measure the average price of an asset over a specified time period, smoothing out price fluctuations to reveal the underlying trend direction and momentum.

When to Use

Period Selection Guidelines

The period parameter significantly affects the moving average's behavior:

Period RangeTimeframeCharacteristicsUse Case
5-10Very ShortHigh responsiveness, more noiseScalping, intraday trading
10-20ShortBalanced sensitivityDay trading, swing entries
20-50MediumModerate smoothingSwing trading, trend identification
50-100LongSmooth, established trendsPosition trading, long-term trends
100-200+Very LongVery smooth, major trendsLong-term investing, macro trends

Common Period Combinations

Traders often use multiple moving averages together:

Default Usage

use rust_ti::moving_average::bulk::moving_average;
use rust_ti::MovingAverageType;

pub fn main() {
    // fetch the data in your preferred way
    // let prices = vec![...];  // price data
    
    // Simple Moving Average
    let ma = moving_average(&prices, MovingAverageType::Simple, 20);
    println!("MA: {:?}", ma);
    
    // Exponential Moving Average
    let ema = moving_average(&prices, MovingAverageType::Exponential, 20);
    println!("EMA: {:?}", ema);
    
    // Smoothed Moving Average
    let sma = moving_average(&prices, MovingAverageType::Smoothed, 20);
    println!("SMA: {:?}", sma);
    
}
import pytechnicalindicators as pti

# Simple Moving Average
ma = pti.moving_average.bulk.moving_average(prices, "simple", 20)
print("MA:", ma)

# Exponential Moving Average
ema = pti.moving_average.bulk.moving_average(prices, "exponential", 20)
print("EMA:", ema)

# Smoothed Moving Average
sma = pti.moving_average.bulk.moving_average(prices, "smoothed", 20)
print("SMA:", sma)
import init, { 
    movingAverage_bulk_movingAverage,
    MovingAverageType 
} from 'https://cdn.jsdelivr.net/npm/ti-engine@latest/dist/web/ti_engine.js';

await init();

// fetch the data in your preferred way
// const prices = [...];  // price data

// Simple Moving Average
const ma = movingAverage_bulk_movingAverage(prices, MovingAverageType.Simple, 20);
console.log("MA:", ma);

// Exponential Moving Average
const ema = movingAverage_bulk_movingAverage(prices, MovingAverageType.Exponential, 20);
console.log("EMA:", ema);

// Smoothed Moving Average
const sma = movingAverage_bulk_movingAverage(prices, MovingAverageType.Smoothed, 20);
console.log("SMA:", sma);

Interactive Chart

Use the interactive playground below to explore how different parameters affect the indicator's behavior.