Skip to main content
Skip to main content
Version: Next 🚧

Moving Averages

Moving averages smooth price data to identify trends by filtering out short-term price fluctuations. They are among the most widely used technical indicators in trading.

Simple Moving Average (SMA)​

Calculation​

The SMA is calculated by taking the arithmetic mean of prices over a specified period.

Formula:

SMA = (P₁ + Pā‚‚ + Pā‚ƒ + ... + Pā‚™) / n

Where:
- P = Price (typically closing price)
- n = Number of periods

Example (5-period SMA):

Prices: 100, 102, 101, 103, 105
SMA = (100 + 102 + 101 + 103 + 105) / 5 = 102.2

Characteristics​

  • Lag: High (equal weight to all periods)
  • Smoothness: Very smooth
  • Responsiveness: Slow to react to price changes
  • Best For: Identifying long-term trends and support/resistance levels

Period Selection​

PeriodUse CaseTimeframe
9Very short-term trendsScalping, 1-5 min
20Short-term trendsDay trading, 15-30 min
50Medium-term trendsSwing trading, 1-4 hour
100Intermediate trendsPosition trading, daily
200Long-term trendsPosition trading, daily/weekly

Usage Examples​

Support/Resistance:

{
"indicator": "sma",
"period": 200,
"comparison": "above",
"value": "close"
}
// Price above 200 SMA = bullish trend

Golden Cross (Bullish):

{
"indicator1": "sma",
"period1": 50,
"indicator2": "sma",
"period2": 200,
"comparison": "crosses_above"
}
// 50 SMA crosses above 200 SMA

Death Cross (Bearish):

{
"indicator1": "sma",
"period1": 50,
"indicator2": "sma",
"period2": 200,
"comparison": "crosses_below"
}
// 50 SMA crosses below 200 SMA

Exponential Moving Average (EMA)​

Calculation​

The EMA gives more weight to recent prices, making it more responsive to new information.

Formula:

EMA = (Close - EMA_previous) Ɨ Multiplier + EMA_previous

Where:
Multiplier = 2 / (Period + 1)

Example (5-period EMA):

Multiplier = 2 / (5 + 1) = 0.333

Day 1: EMA = 100 (use SMA for first value)
Day 2: EMA = (102 - 100) Ɨ 0.333 + 100 = 100.67
Day 3: EMA = (101 - 100.67) Ɨ 0.333 + 100.67 = 100.78
Day 4: EMA = (103 - 100.78) Ɨ 0.333 + 100.78 = 101.52
Day 5: EMA = (105 - 101.52) Ɨ 0.333 + 101.52 = 102.68

Characteristics​

  • Lag: Medium (more weight to recent prices)
  • Smoothness: Moderately smooth
  • Responsiveness: Faster than SMA
  • Best For: Trend following with reduced lag

Period Selection​

PeriodUse CaseTimeframe
9Fast-moving trendScalping, intraday
12MACD fast lineAll timeframes
20Short-term trendDay trading
26MACD slow lineAll timeframes
50Medium-term trendSwing trading
200Long-term trendPosition trading

Usage Examples​

Trend Following:

{
"indicator": "ema",
"period": 20,
"comparison": "above",
"value": "close"
}
// Price above 20 EMA = uptrend

EMA Crossover (Fast Entry):

{
"indicator1": "ema",
"period1": 9,
"indicator2": "ema",
"period2": 21,
"comparison": "crosses_above"
}
// 9 EMA crosses above 21 EMA = bullish

Triple EMA Strategy:

// Entry conditions:
// 1. Price > EMA(9)
// 2. EMA(9) > EMA(21)
// 3. EMA(21) > EMA(50)
// All EMAs aligned = strong uptrend

Weighted Moving Average (WMA)​

Calculation​

The WMA assigns linearly increasing weights to more recent prices.

Formula:

WMA = (P₁ Ɨ 1 + Pā‚‚ Ɨ 2 + Pā‚ƒ Ɨ 3 + ... + Pā‚™ Ɨ n) / (1 + 2 + 3 + ... + n)

Where:
- P = Price
- n = Period
- Sum of weights = n Ɨ (n + 1) / 2

Example (5-period WMA):

Prices: 100, 102, 101, 103, 105
Weights: 1, 2, 3, 4, 5
Sum of weights = 5 Ɨ 6 / 2 = 15

WMA = (100Ɨ1 + 102Ɨ2 + 101Ɨ3 + 103Ɨ4 + 105Ɨ5) / 15
= (100 + 204 + 303 + 412 + 525) / 15
= 1544 / 15
= 102.93

Characteristics​

  • Lag: Medium (linear weighting)
  • Smoothness: Moderately smooth
  • Responsiveness: Between SMA and EMA
  • Best For: Balancing smoothness and responsiveness

Period Selection​

Similar to EMA, but less commonly used:

PeriodUse Case
9-20Short-term trends
20-50Medium-term trends
50-100Long-term trends

Usage Examples​

Trend Confirmation:

{
"indicator": "wma",
"period": 20,
"comparison": "above",
"value": "close"
}
// Price above 20 WMA = bullish

Comparison: SMA vs EMA vs WMA​

Visual Comparison​

Price: 100 → 110 → 105 → 115 → 120

SMA(5): 100.0 → 102.0 → 103.0 → 106.0 → 110.0
EMA(5): 100.0 → 103.3 → 103.9 → 107.3 → 111.5
WMA(5): 100.0 → 103.3 → 104.3 → 108.0 → 112.7

Responsiveness: WMA > EMA > SMA
Smoothness: SMA > EMA > WMA

When to Use Each​

IndicatorBest ForAdvantagesDisadvantages
SMALong-term trends, S/R levelsVery smooth, clear signalsHigh lag, slow response
EMATrend following, dynamic S/RReduced lag, responsiveMore whipsaws
WMABalanced approachGood compromiseLess popular, fewer resources

Common Moving Average Strategies​

1. Moving Average Crossover​

Setup:

  • Fast MA: 9 or 20 period
  • Slow MA: 50 or 200 period

Entry:

  • Long: Fast MA crosses above Slow MA
  • Short: Fast MA crosses below Slow MA

Example:

{
"entryConditions": {
"long": {
"conditions": [
{
"indicator1": "ema",
"period1": 20,
"indicator2": "ema",
"period2": 50,
"comparison": "crosses_above"
}
]
}
}
}

2. Price and MA Crossover​

Setup:

  • Single MA: 20, 50, or 200 period

Entry:

  • Long: Price crosses above MA
  • Short: Price crosses below MA

Example:

{
"entryConditions": {
"long": {
"conditions": [
{
"type": "price_indicator",
"price": "close",
"indicator": "ema",
"period": 50,
"comparison": "crosses_above"
}
]
}
}
}

3. Triple Moving Average​

Setup:

  • Fast: 9 EMA
  • Medium: 21 EMA
  • Slow: 50 EMA

Entry (Long):

  • Price > Fast MA
  • Fast MA > Medium MA
  • Medium MA > Slow MA

Example:

{
"entryConditions": {
"long": {
"logicalOperator": "AND",
"conditions": [
{
"type": "price_indicator",
"price": "close",
"indicator": "ema",
"period": 9,
"comparison": "above"
},
{
"indicator1": "ema",
"period1": 9,
"indicator2": "ema",
"period2": 21,
"comparison": "above"
},
{
"indicator1": "ema",
"period1": 21,
"indicator2": "ema",
"period2": 50,
"comparison": "above"
}
]
}
}
}

4. Moving Average Bounce​

Setup:

  • Dynamic support: 20 or 50 EMA

Entry:

  • Price pulls back to MA
  • Price bounces off MA (doesn't close below)
  • Momentum indicator confirms (RSI > 50)

Example:

{
"entryConditions": {
"long": {
"logicalOperator": "AND",
"conditions": [
{
"type": "price_indicator",
"price": "low",
"indicator": "ema",
"period": 20,
"comparison": "above"
},
{
"type": "indicator_value",
"indicator": "rsi",
"period": 14,
"comparison": "above",
"value": 50
}
]
}
}
}

5. Moving Average Envelope​

Setup:

  • Center: 20 SMA
  • Upper: 20 SMA + 2%
  • Lower: 20 SMA - 2%

Entry:

  • Long: Price touches lower envelope
  • Short: Price touches upper envelope

Period Optimization Guidelines​

Backtesting Approach​

  1. Start with standard periods: 9, 20, 50, 200
  2. Test variations: ±5 periods around standard
  3. Evaluate metrics: Win rate, profit factor, drawdown
  4. Avoid over-optimization: Don't fit to specific data

Market-Specific Periods​

MarketFast MASlow MARationale
Forex8, 13, 2150, 100Fibonacci numbers
Stocks9, 2050, 200Traditional periods
Crypto7, 259924/7 market adjustment
Commodities9, 1840, 100Seasonal patterns

Best Practices​

Do's​

  • āœ… Use EMAs for trend following (less lag)
  • āœ… Use SMAs for support/resistance (more reliable)
  • āœ… Combine with volume for confirmation
  • āœ… Use longer periods for higher timeframes
  • āœ… Wait for candle close before acting on crossovers

Don'ts​

  • āŒ Use moving averages in ranging markets
  • āŒ Rely solely on MA crossovers (many false signals)
  • āŒ Use too many MAs (clutters chart)
  • āŒ Change periods frequently (stick to your system)
  • āŒ Ignore price action in favor of MAs

Common Pitfalls​

1. Whipsaws in Ranging Markets​

Problem: MAs generate false signals when price oscillates Solution: Use ADX to confirm trend strength (ADX > 25)

2. Lagging Signals​

Problem: MAs are lagging indicators Solution: Combine with leading indicators (RSI, Stochastic)

3. Over-Optimization​

Problem: Perfect parameters for past data fail in live trading Solution: Use standard periods, validate with walk-forward testing