Standard Deviation StdDev
The dispersion of the applied price around its own moving average over N bars, in price units.
It measures how widely price has been spread around its centre, which is not the same as how far it has travelled. Readings: high values as a wide phase and low values as a narrow one, with the standing caveat that a narrow phase is a statement about the past window only. The two conventions agree to sub-resolution — the same population deviation reached by different arithmetic.
01The study, live
Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.
What this figure shows
The figure is computed over 300 sample bars. StdDev has no value on the first 19 — the bars it needs before it can answer — and its first value stands on bar 20. Its line runs between 0.00035 and 0.0026 on these bars, and the last value is 0.00088. Counting the conditions the study declares on these bars: turns up 26 times; turns down 26 times. Press a condition under the figure to see each place marked. As states rather than moments: is rising on 152 bars; is falling on 128 bars.
02Its parts, named
03What you see
A line in price units: how spread out the last prices are around their own average.
StdDev is one line in a pane of its own, never below zero. It rises when the closes of the window spread apart — in a burst of volatility and in a steady trend alike — and sinks when they bunch together. It carries no direction.
04Where it comes from
The standard deviation is the statistician's basic measure of spread, in use since the nineteenth century (the name is Karl Pearson's, 1894). In trading it is the ingredient of Bollinger Bands and of every volatility estimate built on closes.
05The formula
σₜ = √(1/N Σ[i=0..N−1] (P_(t−i) − P̄)²)
the population standard deviation of the window.
06A worked example
Take the last five closes of the sample, 22, 24, 25, 24, 26, and a period of 5.
Their average is 24.20. Their distances from it are -2.2, -0.2, 0.8, -0.2, 1.8; squared, 4.84, 0.04, 0.64, 0.04, 3.24. The average of the squares — the variance — is 1.76.
StdDev = √1.76 = 1.33
It is in price units. Squaring before averaging makes one distant close count for much more than several near ones: the close of 22 alone supplies 55 % of the variance here.
07Built in Assay
The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.
//@version=6 indicator("Standard Deviation") length = input.int(20, "Length") // How far the closes spread around their average, over the window: the square root of the mean squared // distance from the mean (divided by `length`, not `length - 1`). deviation = ta.stdev(close, length) plot(deviation, "StdDev")
Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.
08Readings — what traders look for
Rising values are read as prices dispersing more; low values as prices bunched together. It is the width of Bollinger Bands.
How a low reading fails. A low deviation says closes have been bunched together. Quiet stretches end, but the line does not say when or which way.
How a high reading fails. It says closes have been spread out — which a steady trend produces just as a wild range does, because the deviation is measured around an average that lags a trend.
09In different markets and timeframes
The standard deviation measures how spread the closes are around their mean. It rises in a steady trend as well as in disorder, because a trend spreads closes around a lagging mean. It clusters: quiet stretches and wild ones each persist.
10With other studies
It is the width of Bollinger Bands, and BandWidth and %B are read from it. Read beside the ATR, which measures bar size rather than spread of closes.
11What it does not tell you
A standard deviation of prices also grows in a steady trend, because the window's prices are spread along the trend — it is not only a measure of noise.
12Inputs and defaults
- 1Period — 20The window. Short: the line leaps when one unusual close enters and drops when it leaves. Long: a steadier picture of the market's general spread.
- 2Deviations — 1The line is the deviation times this number. 1 is the deviation itself.
- 3Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
- 4Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 5Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
What each input changes
- Applied priceWhich price of each bar is measured.
- DeviationsThe line is the standard deviation times this number. 1 draws the deviation itself; 2 draws the distance a two-deviation band would stand from its average.
- In use20 by default, matched to Bollinger Bands; 10 for a quicker reading.
13Limits and common misreadings
A trend counts as spread. Closes marching steadily upward have a large deviation around their mean without any disorder.
Divides by N, the population form, not N − 1.
14Conditions an alert or a strategy can watch
an event happens on one bar a state holds on every bar while it lasts
These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.
15Practise it in the laboratory
Put StdDev 20 and Bollinger Bands 20 on one chart: the bands' half-width is the deviation times the band multiplier. Replay a steady trend and watch the deviation rise with no change in the bars' size.
Open the laboratory17On pages of their own
18In Bentrix
- From the menu: a chart's Indicators button › Volatility › StdDev, or type StdDev in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
19From an agent or a program
Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "std_dev"}).
The study, as a chart files it
This is a new StdDev’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.
{
"applied": "close",
"convention": "mt5",
"kind": "std_dev",
"settings": {
"period": 20,
"shape": "period"
}
}An agent
An agent calls the MCP tool with it:
{
"name": "study_values",
"arguments": {
"bench": "bentrix://lab/\u2026/bench/\u2026",
"symbol": "EURUSD",
"timeframe": "H1",
"limit": 5,
"study": {
"applied": "close",
"convention": "mt5",
"kind": "std_dev",
"settings": {
"period": 20,
"shape": "period"
}
}
}
}A program
A program does the same in its language — bench and market as in the built-in indicators guide:
Python
values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "mt5", "kind": "std_dev", "settings": {"period": 20, "shape": "period"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
print("line:", line["line"])
print(" newest values:", line["values"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "mt5", "kind": "std_dev", "settings": { "period": 20, "shape": "period" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
console.log("line:", line.line);
console.log(" newest values:", line.values);
}C#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "mt5", ["kind"] = "std_dev", ["settings"] = new Dictionary<string, object?> { ["period"] = 20, ["shape"] = "period" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
Console.WriteLine($"line: {line!["line"]!}");
Console.WriteLine($" newest values: {line!["values"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "mt5", "kind": "std_dev", "settings": map[string]any{"period": 20, "shape": "period"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
fmt.Println("line:", at(line, "line"))
fmt.Println(" newest values:", at(line, "values"))
}Java
Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "mt5", "kind", "std_dev", "settings", obj("period", 20, "shape", "period"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
System.out.println("line:" + " " + at(line, "line"));
System.out.println(" newest values:" + " " + at(line, "values"));
}C++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "mt5"}, {"kind", "std_dev"}, {"settings", Json::Object{{"period", 20}, {"shape", "period"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
std::cout << "line:" << " " << line["line"].dump() << std::endl;
std::cout << " newest values:" << " " << line["values"].dump() << std::endl;
}Julia
values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "mt5", "kind" => "std_dev", "settings" => Dict{String,Any}("period" => 20, "shape" => "period")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
println("line:", " ", line["line"])
println(" newest values:", " ", line["values"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "mt5", kind = "std_dev", settings = list(period = 20, shape = "period")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
cat("line:", format(line$line), "\n")
cat(" newest values:", format(line$values), "\n")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "mt5", "kind": "std_dev", "settings": {"period": 20, "shape": "period"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
println!("line: {}", line["line"]);
println!(" newest values: {}", line["values"]);
}Reading the answer
times— the candles’ open times, in milliseconds since 1970 (UTC), oldest first.lines— one entry per line, in this order, each with itslinename and itsvalues;values[i]belongs to the candle attimes[i].- The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
line | What it is |
|---|---|
Main | the indicator's own value |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here std_dev: {"std_dev": {"applied": "close", "convention": "mt5", "kind": "std_dev", "settings": {"period": 20, "shape": "period"}}} — its rules can name:
| Write | What it is |
|---|---|
std_dev | its main line, as a value in a compare |
{"cond": "std_dev:line.turns_up"} | a condition it declares itself |
{"cond": "std_dev:line.turns_down"} | a condition it declares itself |
{"cond": "std_dev:line.rising"} | a condition it declares itself |
{"cond": "std_dev:line.falling"} | a condition it declares itself |
20Sources
- Murphy, John J. Technical Analysis of the Financial Markets. New York Institute of Finance, 1999.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed