Standard Deviation is a pure volatility indicator — it says nothing about direction, only about how spread out price has been around its own recent average. A low reading means price has been hugging its average tightly; a high reading means price has been swinging far above and below it. There's no overbought zone, no oversold zone, and no fixed range to memorize — it simply rises and falls with how dispersed the market currently is.
How Standard Deviation Is Calculated
Standard Deviation is a statistical measure borrowed directly from general math, not invented for trading. Given a moving average over a set number of bars, it measures the average distance each of those bars' prices sits from that moving average, then takes the square root of that average squared distance. The formula, applied to price, looks like this conceptually:
- Calculate a moving average over the chosen period (the default here is a 20-period Simple Moving Average of the Close).
- For each bar in that period, measure how far its price sits from the moving average (the deviation).
- Square each deviation (so negative and positive deviations don't cancel out), average those squared deviations, then take the square root of the result.
The output is a single number in the same units as price — pips, or fractions of a currency unit — representing the "typical" distance price has strayed from its own average recently. When every bar in the window sits close to the moving average, that distance is small and Standard Deviation reads low. When bars are scattered wide above and below the average — a choppy, volatile stretch — the distance is large and Standard Deviation reads high. It is always zero or positive; it can never go negative, because the squaring step in the formula removes the sign.
Reading Expansion and Contraction
Because Standard Deviation only measures dispersion, its practical use comes down to watching it rise and fall over time rather than reading any single value in isolation. A rising line means the market's swings are getting wider — larger candles, bigger pushes away from the average, in either direction. A falling line means price is compressing into a tighter range around its own average — the market is calming down.
The diagram shows this relationship directly: the price panel on top makes noticeably larger swings around its recent average in the middle of the chart, and the Standard Deviation panel below rises in lockstep during that stretch, then falls back down as price compresses into a quiet range on either side. This rise-and-fall pattern is the entire signal Standard Deviation offers — it never tells you which way price will move next, only how much it has recently been moving.
Entry Conditions
The included indicator doesn't generate a BUY/SELL trade signal on its own — Standard Deviation is a volatility filter, not a directional tool. Instead, the alert logic built into standard-deviation-alert.mq4/.mq5 watches for volatility expansion: it compares the current Standard Deviation reading against the highest reading seen over the previous ExpansionPeriod bars (default 20), and fires an alert the moment Standard Deviation breaks out to a new 20-bar high.
That single event — Standard Deviation expanding beyond its own recent range — flags the start of a bigger-than-usual move, without saying whether that move is up or down. In practice, this is used as a heads-up to pay closer attention to a chart, or as a filter layered on top of a directional system: a trend-following signal or breakout entry taken while Standard Deviation is expanding carries more conviction than the same signal fired during a flat, compressed reading, because the expansion confirms real money is starting to move the market rather than the price simply drifting on noise.
Parameters
- MAPeriod (default 20) — the number of bars the underlying moving average and its deviation are calculated over. A shorter period reacts faster to recent swings but produces a noisier, more jagged line; a longer period smooths the reading out but reacts more slowly to a genuine shift in volatility.
- MAShift (default 0) — shifts the underlying moving average forward or backward on the chart; left at 0 for a standard, unshifted reading.
- MAMethod (default SMA) — the type of moving average the deviation is measured against (Simple, Exponential, Smoothed, or Linear Weighted). SMA is the standard, most widely recognized choice.
- AppliedPrice (default Close) — which price the calculation uses; Close is the standard and most common choice, since it reflects where the market actually settled for each bar.
- ExpansionPeriod (default 20) — the lookback window the alert logic checks Standard Deviation's current reading against; a new high over this window triggers the volatility-expansion alert.
- EnableAlert / EnablePush — toggle the on-screen popup alert and mobile push notification independently when a new expansion signal fires.
Standard Deviation vs ATR: Two Different Volatility Lenses
Standard Deviation and ATR both answer the same question — "how volatile is this market right now?" — but they arrive at the answer from completely different angles, and it's worth being precise about the difference rather than treating them as interchangeable.
ATR measures the average true range of individual candles: the greatest of a candle's own high-low span, or the gap from the previous close, averaged over a period. It answers "how big are the bars themselves getting?" — a bar-by-bar, gap-aware read on raw candle size.
Standard Deviation instead measures how far price has dispersed from its own moving average over a period — a statistical spread calculation borrowed straight from general math, with no concept of individual candle gaps at all. It answers "how scattered is price around its recent center?" A market can produce this distinction clearly: a strong, smooth trend can have fairly ordinary-sized individual candles (keeping ATR moderate) while still pushing price a long way from its moving average over the period (pushing Standard Deviation higher), because Standard Deviation accumulates the distance traveled from the mean, not the size of any one bar. Conversely, a choppy, whippy range with large individual candles that cancel each other out can show elevated ATR alongside a comparatively lower Standard Deviation, because price keeps returning close to its own average even though each bar is large.
Neither reading is "better" — they're complementary lenses on the same underlying question, and many traders find value in glancing at both rather than picking just one.
The Building Block Behind Bollinger Bands
Standard Deviation isn't only useful as a standalone indicator — it's the literal mathematical foundation of Bollinger Bands. A Bollinger Band's upper and lower lines are nothing more than the middle moving average plus and minus a multiple of Standard Deviation (2 standard deviations, by the standard 20, 2 setting). Every time Bollinger Bands widen during a volatile move or squeeze together during a quiet one, that's Standard Deviation rising and falling underneath the surface, translated into a visual envelope around price.
Watching the Standard Deviation indicator directly, rather than only the bands it feeds, has one advantage: it isolates the volatility reading from the band's visual overlap with price, making a genuine expansion or squeeze easier to confirm numerically rather than by eye. A trader who sees a Bollinger Band squeeze and wants confirmation that volatility is genuinely at a multi-week low, not just visually tight, can check the raw Standard Deviation value against its own recent history to be sure.
A Word of Caution
Standard Deviation, like ATR, is calculated from what has already happened — it describes recent dispersion, it doesn't forecast the next one. A low reading can persist for a long stretch before finally breaking into an expansion, and there's no way to know in advance exactly when that will happen or how large the resulting move will be. The expansion alert fires only after Standard Deviation has already made a new high, meaning some of the move it's flagging has already occurred by the time the alert appears — it detects the start of a new volatility regime, not the very first tick of it. And critically, Standard Deviation carries no directional information whatsoever: an expansion reading is equally consistent with a sharp rally and a sharp decline, so it should feed Risk Management Basics and stop-sizing decisions, or sit alongside a directional tool, rather than being traded as a signal by itself.
Download the Indicator
This custom indicator plots Standard Deviation in a separate window and alerts when volatility expands to a new period high. It's available for both MetaTrader 4 and MetaTrader 5 below.
How to Install — MetaTrader 4
- Download the
standard-deviation-alert.mq4file below. - Open MetaTrader 4 → click
File→Open Data Folder. - Place the file in the
MQL4/Indicatorsfolder. - Restart MetaTrader 4, then drag the indicator from the Navigator window onto the chart.
How to Install — MetaTrader 5
- Download the
standard-deviation-alert.mq5file below. - Open MetaTrader 5 → click
File→Open Data Folder. - Place the file in the
MQL5/Indicatorsfolder. - Restart MetaTrader 5, then drag the indicator from the Navigator window onto the chart.
Both files are source code — open and review the full code before using it, for your own safety.