Simple Moving Average
systemic:core-smaIndicatorsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Window | integer | The number of periods to include in each average calculation—the "lookback" period. |
| Price | floatarray | The numeric series to be smoothed by the moving average calculation. |
Outputs
| Name | Type | Description |
|---|---|---|
| SMA | floatarray | The smoothed average series, with one value for each input data point. |
The Art of Smoothing
In 1833, the Bank of England faced a delicate problem: how to report its bullion reserves without revealing the volatile daily fluctuations that might alarm the public. Their solution? Average the numbers over time. This technique—the moving average—was literally invented to smooth out an inconvenient truth.
Nearly two centuries later, the same principle underlies every chart in every trading platform: the average reveals the trend that noise obscures.
The formula is deceptively simple—just divide the sum of prices by . But this simplicity is the source of both its power and its philosophical depth: every observation receives equal weight. Yesterday's price matters exactly as much as the price from 20 days ago.
Why Equal Weight Matters
The SMA treats all data points within its window as equally important. This is a deliberate philosophical choice, not a limitation:
- Equal weight = democratic memory. The SMA doesn't privilege recent information over older information. This creates stability but introduces lag.
- Symmetry creates objectivity. No arbitrary weighting decisions mean everyone calculates the same SMA from the same data.
- The 200-day SMA as consensus. When millions of traders watch the same line, it becomes a self-fulfilling reference point.
This is why the 50-day and 200-day SMAs are institutional standards—not because they're mathematically optimal, but because everyone agrees to watch them.
The Rolling Window
flowchart LR
subgraph Window["Rolling Window (n periods)"]
direction TB
P1["P₁"]
P2["P₂"]
Dots["···"]
Pn["Pₙ"]
end
Window --> Sum["Sum"] --> Divide["÷ n"] --> SMA["SMA Value"]
As each new price arrives:
- The oldest price exits the window
- The newest price enters the window
- A new average is calculated
This creates the characteristic "lag"—the SMA always trails the actual price because it's averaging past data.
Missing Data
"N-bar" means N observed bars, not N calendar slots. A closed-market or missing-data slot is skipped when assembling the window, and a Friday-close-to-Monday-open average is computed over adjacent trading bars — the weekend gap is bridged, never treated as a zero or a repeated value.
- Gaps are bridged, not broken: the window always contains N genuine observations; a gap does not shrink the window and does not get silently averaged over as if it were a real bar.
- Warm-up is null, not partial: the first
window - 1observed bars have no complete window yet and are null — never a partial-window average of fewer bars than the user configured. - Interior and trailing gaps stay null in place: a missing slot never receives a substitute value, so the SMA never fabricates a data point where none exists.
- Live execution returns exactly one datapoint — the newest — which is null when the current bar's window is not yet complete or its data is missing.
Standard Periods and Their Meanings
| Period | Timeframe | What Traders Watch For |
|---|---|---|
| 10 | Short-term | Momentum shifts, quick reactions |
| 20 | Short-term | Swing trading entries, mean reversion |
| 50 | Medium-term | Institutional interest, trend confirmation |
| 100 | Medium-term | Major trend health |
| 200 | Long-term | Bull/bear market definition, major support/resistance |
💡 The 200-day SMA is perhaps the most watched line in all of finance. Many define a bull market as price trading above the 200 SMA, and a bear market as price trading below it.
Trading Signals
Price Crossovers
| Price Action | Signal | Interpretation |
|---|---|---|
| Price crosses above SMA | Bullish | Momentum shifting upward |
| Price crosses below SMA | Bearish | Momentum shifting downward |
| Price bounces off SMA from above | Support | Uptrend intact |
| Price rejected at SMA from below | Resistance | Downtrend intact |
Golden Cross & Death Cross
The most famous SMA signals involve two moving averages:
| Pattern | Definition | Significance |
|---|---|---|
| Golden Cross | 50 SMA crosses above 200 SMA | Major bullish signal—often marks start of bull markets |
| Death Cross | 50 SMA crosses below 200 SMA | Major bearish signal—often marks start of bear markets |
flowchart LR
subgraph GoldenCross["🟢 Golden Cross"]
G1["50 SMA rising"]
G2["Crosses above 200 SMA"]
end
subgraph DeathCross["🔴 Death Cross"]
D1["50 SMA falling"]
D2["Crosses below 200 SMA"]
end
G1 --> G2
D1 --> D2
⚠️ Caveat: These crosses are lagging by nature. By the time a Golden Cross appears, much of the move may already be priced in. Use them for trend confirmation, not timing.
The Lag Problem—Or Is It?
Critics often dismiss the SMA because it "lags." But this criticism misunderstands its purpose:
| Perspective | Lag Is A Problem When... | Lag Is An Advantage When... |
|---|---|---|
| Trading | You need precise entry/exit timing | You want to filter out false moves |
| Trend Following | Trends are short-lived | Trends are long and sustained |
| Volatility | Markets are choppy | Markets are trending cleanly |
The SMA is not designed for timing. It's designed for trend identification and noise reduction. If you need faster signals, consider the EMA or other weighted averages.
Multiple SMA Systems
Sophisticated traders layer multiple SMAs to build a confluence of signals:
The "Perfect Order" Setup:
- Price > 20 SMA > 50 SMA > 200 SMA = Strong uptrend
- Price < 20 SMA < 50 SMA < 200 SMA = Strong downtrend
Pullback Trading:
- Confirm uptrend (price above 200 SMA)
- Wait for pullback to 20 or 50 SMA
- Enter on bounce with trend
When It Excels
- Strong trending markets — The SMA keeps you on the right side
- Long timeframes — Daily, weekly charts where noise is less dominant
- Institutional stocks — Where many participants watch the same levels
- Confirming other signals — As a filter for entries/exits from other indicators
When It Struggles
- Sideways/choppy markets — Generates whipsaws and false signals
- Fast-moving markets — Lag means missed entries and late exits
- Short timeframes — Too much noise relative to trend
- Volatile assets — May never provide clean signals
A Brief Note on SMA vs. EMA
| Characteristic | SMA | EMA |
|---|---|---|
| Weight distribution | Equal | Exponentially decaying |
| Responsiveness | Slower | Faster |
| Lag | More | Less |
| Noise filtering | Better | Worse |
| Best for | Trend definition | Signal timing |
The SMA is objectively simpler but not inferior. The choice depends on your goal.
Summary
| Aspect | Detail |
|---|---|
| Full Name | Simple Moving Average |
| Purpose | Smooth price data to reveal underlying trend |
| Formula | |
| Key Insight | Equal weighting = democratic, objective, stable |
| Classic Signals | Price crossovers, Golden/Death Cross |
| Strength | Noise reduction, institutional consensus |
| Weakness | Lagging, whipsaws in ranges |
| Best Periods | 10, 20, 50, 100, 200 (context-dependent) |
Indicator Assessment
%%{init: {"quadrantChart": {"titleFontSize": 16}}}%%
quadrantChart
title SMA Indicator Assessment
x-axis Low Complexity --> High Complexity
y-axis Low Reliability --> High Reliability
quadrant-1 Complex but Reliable
quadrant-2 Simple and Reliable
quadrant-3 Simple but Unreliable
quadrant-4 Complex and Unreliable
SMA - Stocks: [0.15, 0.75]
SMA - Crypto: [0.15, 0.60]
| Dimension | Stocks/Macro | Crypto | Notes |
|---|---|---|---|
| Popularity | 10/10 | 10/10 | The most widely used indicator in existence—literally on every trading platform |
| Reliability | 7.5/10 | 6/10 | Excellent in trending markets; generates whipsaws in ranges. Crypto's higher volatility causes more false signals |
| Complexity | 1/10 | 1/10 | Elementary school arithmetic—sum and divide. No parameters beyond window size |
| Versatility | 9/10 | 8/10 | Works on any asset, any timeframe. Crypto's 24/7 markets change period interpretation slightly |
| Recent Interest | 7/10 | 7/10 | Steady baseline interest. Not trendy but never obsolete—the "jeans and t-shirt" of indicators |
Assessment Rationale
Popularity (10/10): The SMA is the original technical indicator. It predates modern computing, appears in every charting platform, and is the foundation for dozens of derivative indicators (Bollinger Bands, MACD, envelopes). Its popularity is unparalleled.
Reliability (7.5/10 Stocks, 6/10 Crypto): In trending markets, the SMA performs admirably—keeping traders on the right side of major moves. The 200-day SMA's bull/bear classification has proven remarkably consistent over decades of market history. However, in ranging or choppy conditions, it generates numerous whipsaws. Cryptocurrency markets, with their higher volatility and more frequent regime changes, see more false signals.
Complexity (1/10): This is as simple as indicators get. The formula requires only addition and division. No smoothing factors, no weighting schemes, no multi-step calculations. A child can compute an SMA by hand.
Versatility (9/10 Stocks, 8/10 Crypto): The SMA adapts to any asset class and any timeframe. It works on equities, forex, commodities, and cryptocurrencies equally well. The slight reduction for crypto reflects the different market structure (24/7 trading) which changes how "daily" periods are interpreted.
Recent Interest (7/10): The SMA enjoys steady, reliable interest. It's neither trendy nor obsolete—it's the baseline indicator that never goes out of style. Every generation of traders learns it, uses it, and passes it on.