Systemicalpha

Simple Moving Average

systemic:core-smaIndicatorsfunction1 cr

Inputs

NameTypeDescription
WindowintegerThe number of periods to include in each average calculation—the "lookback" period.
PricefloatarrayThe numeric series to be smoothed by the moving average calculation.

Outputs

NameTypeDescription
SMAfloatarrayThe 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.

SMAn=1n∑i=1nPiSMA_n = \frac{1}{n}\sum_{i=1}^{n} P_i

The formula is deceptively simple—just divide the sum of nn prices by nn. 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:

  1. The oldest price exits the window
  2. The newest price enters the window
  3. 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 - 1 observed 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

PeriodTimeframeWhat Traders Watch For
10Short-termMomentum shifts, quick reactions
20Short-termSwing trading entries, mean reversion
50Medium-termInstitutional interest, trend confirmation
100Medium-termMajor trend health
200Long-termBull/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 ActionSignalInterpretation
Price crosses above SMABullishMomentum shifting upward
Price crosses below SMABearishMomentum shifting downward
Price bounces off SMA from aboveSupportUptrend intact
Price rejected at SMA from belowResistanceDowntrend intact

Golden Cross & Death Cross

The most famous SMA signals involve two moving averages:

PatternDefinitionSignificance
Golden Cross50 SMA crosses above 200 SMAMajor bullish signal—often marks start of bull markets
Death Cross50 SMA crosses below 200 SMAMajor 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:

PerspectiveLag Is A Problem When...Lag Is An Advantage When...
TradingYou need precise entry/exit timingYou want to filter out false moves
Trend FollowingTrends are short-livedTrends are long and sustained
VolatilityMarkets are choppyMarkets 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:

  1. Confirm uptrend (price above 200 SMA)
  2. Wait for pullback to 20 or 50 SMA
  3. 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

CharacteristicSMAEMA
Weight distributionEqualExponentially decaying
ResponsivenessSlowerFaster
LagMoreLess
Noise filteringBetterWorse
Best forTrend definitionSignal timing

The SMA is objectively simpler but not inferior. The choice depends on your goal.


Summary

AspectDetail
Full NameSimple Moving Average
PurposeSmooth price data to reveal underlying trend
FormulaSMAn=1n∑i=1nPiSMA_n = \frac{1}{n}\sum_{i=1}^{n} P_i
Key InsightEqual weighting = democratic, objective, stable
Classic SignalsPrice crossovers, Golden/Death Cross
StrengthNoise reduction, institutional consensus
WeaknessLagging, whipsaws in ranges
Best Periods10, 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]
DimensionStocks/MacroCryptoNotes
Popularity10/1010/10The most widely used indicator in existence—literally on every trading platform
Reliability7.5/106/10Excellent in trending markets; generates whipsaws in ranges. Crypto's higher volatility causes more false signals
Complexity1/101/10Elementary school arithmetic—sum and divide. No parameters beyond window size
Versatility9/108/10Works on any asset, any timeframe. Crypto's 24/7 markets change period interpretation slightly
Recent Interest7/107/10Steady 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.


Further Reading

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5