How it works
A simple moving average replaces each bar with the arithmetic mean of the last N closes and plots that mean as a line. Nothing is weighted, nothing is discounted: a close from twenty days ago counts exactly as much as this morning's. The result is a smoothed version of the price series in which single-bar noise has been averaged away and the underlying drift is left visible.
The intuition is worth stating plainly, because it explains almost everything the tool does well and badly. An average is a memory. A 200-day SMA is the market's opinion of fair value as expressed by the last 200 sessions, and it can only change by the difference between the bar entering the window and the bar leaving it. That is why the line turns slowly, why it lags a genuine reversal, and why it is so stable in the middle of a trend. The lag is roughly half the window — a 20-period average sits about ten bars behind a sustained move — and it is not a defect that a cleverer formula removes, it is the price paid for the smoothing.
Traders read three things from it. The first is level: price above a rising average is the crudest workable definition of an uptrend, and it is used as a regime filter far more often than as a signal. The second is slope, which separates a genuine trend from a market that happens to be sitting above a flat line. The third is separation, the distance between price and the average, which tends to mean-revert — an instrument stretched several percent above its 50-day average has usually run ahead of itself. Crossovers between two lengths, the fifty crossing the two hundred being the famous one, compress level and slope into a single discrete event that a system can trade.
Against its neighbours, the SMA is the honest baseline. The exponential average reacts faster to new information and the weighted and Hull variants faster still, but every one of them buys that speed by giving recent bars more influence, which means more sensitivity to a single spike. The SMA is the one that will not be fooled by one bar, and it is the one whose value you can compute in your head. Most of the moving-average family exists to shave lag off this line; whether that trade is worth making depends entirely on whether your strategy is hurt more by being late or by being wrong.
Calculation
The arithmetic in words, in the order it happens.
Add the last N values of the chosen source — closes by default — and divide by N. Each new bar adds the newest value to the window and drops the oldest, so the line moves by the newest value minus the dropped value, divided by N. Every observation in the window carries the same weight of 1/N, and the average is undefined until N bars exist.
Source
An AlgoBeamScript implementation of the formula above, written by us from the arithmetic so the code and the calculation agree line for line.
Runs unchanged on the platform and in the AlgoBeamTS runtime. The language reference is in the documentation.
Inputs
Defaults are the values most charting packages ship with. They are conventions, not optimal settings — the right length depends on your instrument and your holding period.
| Input | Default | What it changes |
|---|---|---|
| Length | 20 | How many bars go into the window. Shorter lengths hug price and turn quickly at the cost of far more false turns; longer lengths ignore noise but confirm reversals late. 20 is the common swing setting, 50 the intermediate-trend line, 200 the long-term regime line. |
| Source | Close | Which price feeds the average. Close is standard. Using the midpoint of high and low, or the typical price of high, low and close, gives a slightly steadier line on instruments with erratic closes such as thin small caps or weekend crypto. |
| Offset | 0 | Shifts the plotted line forward or back in time without changing its values. A positive offset displaces the average into the future, which some breakout systems use so that the line is not touched by the same bar that created it. |
How to read it
What practitioners take from the plot. Read these as descriptions of market state, not as entry signals.
- Price above a rising average
- The simplest definition of an uptrend: recent trade is happening above the market’s own recent mean, and that mean is climbing. Best used as a permission filter for long setups rather than as an entry.
- Flat average, price crossing repeatedly
- No trend to follow. The average has no slope, so crossovers are noise. This is the regime in which moving-average systems bleed money on costs.
- Shorter average crossing above a longer one
- Recent trade has moved decisively above the longer-term mean. A late but relatively durable confirmation that the trend has changed hands; it arrives well after the actual low.
- Price stretched far from the average
- The move has run ahead of its own mean. Distance tends to revert, so this argues for tightening stops or waiting for a pullback rather than chasing.
- Pullbacks stalling at the average
- The line is acting as a moving reference level, partly because so many participants watch the same lengths. Repeated respect of the same average is evidence the trend is still organised.
Limitations
Where this indicator misleads. None of these are fixed by a better parameter.
- It lags by roughly half its length, so it can never mark a turn, only confirm one after the fact. In a sharp V-shaped reversal the average is still pointing the wrong way while price makes a new extreme.
- In a sideways market it whipsaws relentlessly. Price oscillates across a flat line, generating a stream of crossovers that are all noise, and a crossover system hands back in chop what it earned in the last trend.
- Every bar in the window has equal weight, so a single outlier distorts the line for the entire N bars and then distorts it again, in the opposite direction, on the day it drops out of the window.
- The popular lengths carry no structural magic. Optimising the length on past data is one of the easiest ways to overfit, because trend systems earn their return from a handful of large moves and the best length in hindsight is simply the one that caught them.
Educational reference. This page explains how an indicator is built and how it is commonly read. It is not investment advice, not a recommendation and not a signal service. No indicator is profitable on its own — each is a way of describing a market, and any rule built on one has to be tested with realistic costs before it is traded.