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ā
| Period | Use Case | Timeframe |
|---|---|---|
| 9 | Very short-term trends | Scalping, 1-5 min |
| 20 | Short-term trends | Day trading, 15-30 min |
| 50 | Medium-term trends | Swing trading, 1-4 hour |
| 100 | Intermediate trends | Position trading, daily |
| 200 | Long-term trends | Position 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ā
| Period | Use Case | Timeframe |
|---|---|---|
| 9 | Fast-moving trend | Scalping, intraday |
| 12 | MACD fast line | All timeframes |
| 20 | Short-term trend | Day trading |
| 26 | MACD slow line | All timeframes |
| 50 | Medium-term trend | Swing trading |
| 200 | Long-term trend | Position 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:
| Period | Use Case |
|---|---|
| 9-20 | Short-term trends |
| 20-50 | Medium-term trends |
| 50-100 | Long-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ā
| Indicator | Best For | Advantages | Disadvantages |
|---|---|---|---|
| SMA | Long-term trends, S/R levels | Very smooth, clear signals | High lag, slow response |
| EMA | Trend following, dynamic S/R | Reduced lag, responsive | More whipsaws |
| WMA | Balanced approach | Good compromise | Less 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ā
- Start with standard periods: 9, 20, 50, 200
- Test variations: ±5 periods around standard
- Evaluate metrics: Win rate, profit factor, drawdown
- Avoid over-optimization: Don't fit to specific data
Market-Specific Periodsā
| Market | Fast MA | Slow MA | Rationale |
|---|---|---|---|
| Forex | 8, 13, 21 | 50, 100 | Fibonacci numbers |
| Stocks | 9, 20 | 50, 200 | Traditional periods |
| Crypto | 7, 25 | 99 | 24/7 market adjustment |
| Commodities | 9, 18 | 40, 100 | Seasonal 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
Related Documentationā
- Indicators Overview - All available indicators
- Trend Indicators - MACD, ADX, Parabolic SAR
- How to Use Moving Averages - Practical guide
- EMA Crossover Strategy Tutorial - Step-by-step implementation