All posts
Education2026/06/05Updated: By Iven W.

Simple Moving Average (SMA): Formula and TradingView Settings

Learn the SMA formula, TradingView Length, Source and Offset settings, closed-bar timing, platform differences and a reproducible verification workflow.

A Simple Moving Average (SMA) is the arithmetic mean of a selected price source over the most recent n chart bars. On TradingView, the reproducible setup is defined by the exact indicator, Length, Source, Offset, chart interval, session and data feed. An SMA smooths historical data; it does not forecast the next bar, prove that support will hold, or create a complete trading system by itself.

Last verified: August 5, 2026, against TradingView's current Simple Moving Average and Moving Averages documentation.

Key Takeaways

  • The standard SMA gives every value in the lookback window equal weight.
  • Length = 200 means 200 bars on the calculation interval, not automatically 200 calendar days.
  • TradingView's primary SMA inputs are Length, Source and Offset; data, session and bar settings can also change the result.
  • A live-bar SMA can move before the candle closes. A closed-bar rule should evaluate only completed values.
  • Common lengths such as 20, 50 and 200 are reference versions, not universal best settings.
  • Strategy selection belongs in the moving-average strategy testing guide; this page owns SMA calculation and platform consistency.

What This Page Owns

This guide focuses on four questions:

  1. How is an SMA calculated?
  2. Which TradingView inputs and chart settings determine the line?
  3. Why can two platforms display different SMA values?
  4. How can you verify an SMA without hindsight?

For the wider family of SMA, EMA, WMA, DEMA, KAMA, VWMA and other averages, use the Moving Averages TradingView hub. For the calculation and initialization of the faster weighted alternative, use the EMA TradingView tutorial.

The SMA Formula

Let:

  • Xₜ be the selected source value on bar t;
  • n be the SMA length;
  • SMAₜ(n) be the n-period average available on bar t.

The standard formula is:

SMAₜ(n) = (Xₜ + Xₜ₋₁ + ... + Xₜ₋ₙ₊₁) / n

Every observation receives the same weight:

Weight of each value = 1 / n

A 20-period SMA assigns 1/20, or 5%, to each of the 20 source values. A 200-period SMA assigns 1/200, or 0.5%, to each value.

Worked five-bar example

Assume the selected source is Close and the five completed closes are:

BarClose
110
212
314
416
518

The five-period SMA is:

(10 + 12 + 14 + 16 + 18) / 5 = 14

When the next completed close is 20, the oldest value leaves the window:

(12 + 14 + 16 + 18 + 20) / 5 = 16

The line changes because the rolling window changed, not because the indicator detected buyer or seller intent.

Rolling-update identity

The same calculation can be expressed as:

SMAₜ = SMAₜ₋₁ + (Xₜ - Xₜ₋ₙ) / n

This identity shows exactly what moves the average:

  • the newest value enters;
  • the value that is n bars old exits;
  • the difference is divided by the length.

A large new close may have little effect when the removed close is also large. Conversely, the SMA can move even when the current close changes only slightly if an unusually high or low old value drops out of the window.

Warm-Up and the First Valid Value

A strict n-period SMA needs n valid source observations. Before that point, the standard full-window value is unavailable.

A reproducible implementation should state whether it:

  • returns no value until n observations exist;
  • calculates a partial average during warm-up;
  • fills missing values;
  • starts from a longer hidden history than the chart displays;
  • resets at a session, contract or dataset boundary.

TradingView's built-in Simple Moving Average uses the selected length and source over the available series. When comparing platforms, load enough history for the entire window and compare bars well after the warm-up boundary.

How to Add the Built-In SMA in TradingView

TradingView documents Simple Moving Average as a built-in indicator with Length, Source and Offset inputs.

1. Open the Indicators menu

Open Indicators on the chart and search for Simple Moving Average.

2. Select the built-in indicator

Choose TradingView's built-in Simple Moving Average rather than assuming a community script uses the same formula or defaults.

3. Open the Inputs settings

Record the exact values before taking screenshots, testing a signal or comparing another platform.

InputWhat it controlsReproducibility note
LengthNumber of calculation barsRecord the number and the calculation interval
SourceInput series averaged on each barClose is common, but it is not the only possible source
OffsetVisual shift of the plotted lineUse zero for a contemporaneous version unless a shifted plot is explicitly studied

4. Record the chart and data context

The indicator settings alone are not enough. Also record:

  • symbol and venue;
  • data provider;
  • chart interval;
  • session template;
  • timezone and bar boundaries;
  • adjusted or unadjusted stock history;
  • futures contract or continuous-series method;
  • whether the current bar is complete;
  • the date and platform version checked.

5. Style without changing the calculation

Line color, thickness and visibility do not change SMA values. They should not be confused with inputs that affect the calculation.

What Length Actually Means

An SMA length counts bars on its calculation interval.

VersionObservations included
20 SMA on a five-minute chart20 five-minute bars
50 SMA on an hourly chart50 hourly bars
200 SMA on a daily chart200 daily bars produced by the selected session and provider
40 SMA on a weekly chart40 weekly bars

Calling every 200-period line a “200-day SMA” is incorrect when the calculation interval is not daily.

If a platform allows an indicator to use a different interval from the chart, record both:

Chart interval: 15 minutes
SMA calculation interval: Daily
Length: 200
Source: Close

The daily value may remain unchanged across many 15-minute chart bars and then update when the daily calculation bar changes.

Length, Lag and Noise

A longer SMA changes more slowly because each new value receives a smaller weight and a larger historical window remains in the calculation.

This produces a trade-off:

Shorter lengthLonger length
Responds faster to recent changesResponds more slowly
Follows price more closelyProduces a smoother line
Changes state more oftenChanges state less often
Can create more crosses in a rangeCan identify a transition later

This does not establish that one length is better. It describes how the filter changes.

The numbers 20, 50, 100 and 200 are common conventions. They should be treated as named versions that can be compared, not as optimal parameters discovered in advance.

Source Changes the Indicator

Close is a common source, but an SMA can average any numeric series made available by the platform.

Examples include:

  • Open;
  • High;
  • Low;
  • Close;
  • midpoint combinations such as HL2;
  • typical-price combinations such as HLC3;
  • another indicator output;
  • volume, when a volume series is explicitly selected.

A close-based SMA and an HL2-based SMA are separate versions. They may have the same length and still produce different values, slopes and cross events.

Record the source by name and, for a composite source, record its formula.

Offset Changes Alignment, Not Information

TradingView's Offset input shifts the plotted line forward or backward relative to the chart.

Offset does not make future data available. A positive visual shift can place a historical SMA value under a later bar, but the value was still calculated from the data available at its original calculation time.

For ordinary analysis and testing:

Offset = 0

If a nonzero offset is studied, preserve two timestamps:

  1. calculation timestamp — when the SMA value became available;
  2. display timestamp — where the shifted value appears visually.

Using the display position as though it were the calculation time creates look-ahead error.

Closed Bars Versus a Developing Bar

When the selected source includes the current bar's live value, the SMA can change while that bar is still forming.

During one bar:

  1. the current price rises;
  2. the current SMA rises;
  3. price falls before the close;
  4. the final SMA finishes at a different value;
  5. a provisional cross or slope change disappears.

Choose one information policy before testing:

  • closed-bar version: evaluate after the calculation bar closes;
  • developing-bar version: evaluate provisional values and preserve intrabar data;
  • first-cross version: record the first intrabar event;
  • close-survival version: require the event to remain through the bar close.

A closed-bar study should not use an intrabar value that was unavailable after completion.

Define SMA States Precisely

An SMA is a number. Terms such as “bullish,” “support,” “uptrend” and “break” are interpretations that require separate rules.

Price relationship

Above state: Closeₜ > SMAₜ
Below state: Closeₜ < SMAₜ
Equal state: Closeₜ = SMAₜ, or inside a declared tolerance

SMA slope

One simple one-bar slope measure is:

Slopeₜ = SMAₜ - SMAₜ₋₁

Possible states are:

  • rising when Slopeₜ > 0;
  • falling when Slopeₜ < 0;
  • flat when the slope is zero or inside a declared tolerance.

A one-bar sign is sensitive to noise. A research version may instead compare values several bars apart or normalize the change by price or ATR. Any such rule is an added version, not part of the SMA formula.

Price-cross event

A strict closed-bar upward price cross can be defined as:

Closeₜ₋₁ ≤ SMAₜ₋₁
and
Closeₜ > SMAₜ

A price cross is different from a fast-SMA/slow-SMA cross. Strategy families, confirmation and failure testing are covered in the moving-average strategy testing guide.

Golden Cross and Death Cross Are Separate Event Versions

The classic labels normally refer to the 50-day SMA crossing the 200-day SMA:

  • Golden Cross: 50-day SMA moves from not above to above the 200-day SMA;
  • Death Cross: 50-day SMA moves from not below to below the 200-day SMA.

Those names do not define:

  • equality and precision handling;
  • closed-bar or intrabar timing;
  • data source and adjustment policy;
  • confirmation;
  • failure or recross;
  • an entry, stop, target or holding period.

For those exact event and replay-testing controls, use the Golden Cross and Death Cross rules guide.

SMA Versus EMA

Both indicators smooth a historical source, but they weight observations differently.

PropertySMAEMA
WeightingEqual across the rolling windowMore weight on recent observations
Oldest included valueLeaves the window after n barsInfluence decays through the recurrence
ResponseUsually slower and smootherUsually faster and more sensitive
Initialization issueNeeds a full-window policyNeeds a seed and warm-up policy
Main comparison riskDifferent source/session/historyDifferent seed/provider/implementation

Neither method is universally superior. The choice depends on the versioned question and the cost of lag versus noise.

For EMA calculation, multiplier and initialization details, use the EMA TradingView tutorial.

Does an SMA Act as Support or Resistance?

A chart may show repeated reactions near an SMA, but the line is not a standing order book and does not reveal who traded there.

To test an “SMA reaction” claim, define:

  • exact SMA version;
  • approach direction;
  • line or tolerance zone;
  • touch by wick, close or another price field;
  • maximum penetration;
  • reaction measure;
  • confirmation delay;
  • failure and expiry;
  • comparison benchmark.

Without those definitions, selecting only attractive rebounds creates hindsight bias.

For objective price-level definitions independent of an SMA, use the support and resistance guide.

Why Two Platforms Can Show Different SMA Values

The arithmetic formula is simple, but the input series may not be identical.

DifferenceHow it changes the SMA
Symbol or venuePrices and trading hours differ
Data providerHistorical bars and corrections differ
Session templateIncluded bars and daily closes differ
TimezoneIntraday and daily boundaries can move
Stock adjustmentsSplits and distributions can rewrite historical prices
Futures constructionContract rolls and back-adjustment alter the series
Missing barsWindow membership changes
SourceClose, HL2 and other inputs are different series
LengthWindow size and first valid bar change
OffsetDisplay alignment changes
Live-bar stateProvisional values differ from completed values
PrecisionNear-equality and displayed rounding can differ

Do not begin by assuming one platform is wrong. Freeze the complete version and compare the same completed timestamp.

A Reproducible TradingView Verification Workflow

Step 1: Freeze a version card

Indicator: TradingView built-in Simple Moving Average
Symbol/venue:
Provider:
Chart interval:
Calculation interval:
Session:
Timezone:
Source:
Length:
Offset:
Adjustment/roll policy:
Closed-bar policy:
Checked date:

Step 2: Select a completed bar

Choose a bar with at least n prior valid observations. Avoid the first few valid bars if another platform may use a different warm-up history.

Step 3: Export or record the source values

Capture the exact n source values that belong to the window.

Step 4: Calculate the arithmetic mean

Add the values and divide by n. Preserve enough decimal precision to compare with the platform's underlying value rather than only the rounded label.

Step 5: Compare timestamps

Confirm that the manual value and the plotted value refer to the same calculation bar, not a visually shifted Offset position.

Step 6: Change one input at a time

Test Length, Source, interval or session separately. Changing several inputs at once does not identify which one caused the difference.

Step 7: Record unresolved cases

Classify the result as:

  • exact match;
  • match within declared rounding tolerance;
  • mismatch explained by an input difference;
  • mismatch explained by data history;
  • unresolved because required source data is unavailable.

Review SMA Behavior With Chart Replay

Chart replay can show how an SMA state evolves without revealing later candles.

A controlled review can use this sequence:

  1. freeze one symbol, interval, session, source, length and Offset;
  2. hide future candles;
  3. advance one completed bar at a time;
  4. record the SMA value, slope and price relationship;
  5. mark candidates without treating them as trades;
  6. record crosses, recrosses, flat periods and ambiguous equalities;
  7. compare results across a development sample and a later evaluation sample.

You can use ChartMini chart replay for candle-by-candle review when the current chart setup provides the required moving-average indicator. ChartMini does not certify the formula, choose settings, reproduce every provider's data, or simulate full broker execution, slippage and fills.

For a broader historical-test process, use the backtesting guide.

Common SMA Errors

Treating a common length as an optimal length

A widely recognized parameter may be useful as a baseline, but popularity is not evidence that it is best for a particular instrument or objective.

Calling every 200-period average a 200-day SMA

The unit is bars. State the interval.

Comparing a live bar with a completed bar

A provisional current value can disappear before the close.

Ignoring Source

A close-based SMA and an HL2-based SMA are not the same indicator version.

Using Offset as prediction

A shifted plot does not contain future information.

Turning description into a trade rule

“Price is above a rising SMA” describes a chart state. It does not define entry, execution, loss limit or exit.

Counting only favorable reactions

A valid review must also record penetrations, failed reactions, ranges, recrosses and no-resolution cases.

Frequently Asked Questions

What is the Simple Moving Average formula?

For an n-period SMA, add the selected source value from the most recent n bars and divide by n. Using closing prices, SMA = (Close1 + Close2 + ... + Closen) / n. Each completed new bar adds one value and removes the oldest value from the rolling window.

How do I add a Simple Moving Average in TradingView?

Open TradingView's Indicators menu, search for Simple Moving Average, and select the built-in indicator. Open its settings and record the Length, Source and Offset values. For a contemporaneous calculation, keep Offset at zero unless a shifted plot is the subject of the test.

What do Length, Source and Offset change in TradingView's SMA?

Length sets the number of chart bars in the rolling average. Source selects the input series, such as Close, Open, High, Low or another available price field. Offset moves the plotted line forward or backward on the chart; it changes visual alignment, not the underlying historical information available at each bar.

Is the 200-day SMA the best moving average?

No. The 200-day SMA is a common long-horizon reference, but it is not universally best. A useful length depends on the instrument, chart interval, decision horizon, data construction and the rule being tested. Compare candidate lengths with the same frozen data and out-of-sample process rather than choosing one from hindsight.

Why can the same SMA differ between platforms?

Two platforms can show different SMA values when they use different symbols, data providers, sessions, timezones, bar boundaries, adjusted stock history, futures roll methods, missing-bar policies, source fields, lengths, offsets or live-bar states. Match every input and compare completed bars before treating the difference as a calculation error.

Can ChartMini be used to review SMA behavior?

ChartMini can be used for candle-by-candle chart replay and, where the current chart setup provides the required moving-average indicator, for reviewing how an SMA state changes as bars become available. It does not certify the formula, select an optimal length, reproduce every provider's data, or model broker fills and execution costs.

Sources and Method Notes

The formula and platform-input sections were checked against TradingView's current support documentation on August 5, 2026. Strategy examples are framed as research versions rather than recommendations. Hypothetical chart outcomes should be kept separate from trade simulations that include order timing, costs, slippage, liquidity and exits.