Sidechair

ta.stdev()

Browse the reference

Returns the standard deviation of source over the last length bars, dividing by length unless biased is false.

Try it in the editor

ta.stdev is the square root of ta.variance: the mean squared distance of each value from the window's mean. With the default biased = true the sum is divided by length, which is the population form used by Bollinger Bands.

Setting biased to false divides by length - 1, the sample form. The deviation is na until the window holds length values, and while it holds an na.

Syntax

Pine Script
ta.stdev(source: series int/float, length: series int, biased: series bool (optional)) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredThe series whose spread around its own mean is measured over length bars.
lengthseries intrequiredNumber of bars in the window. A whole number of 1 or more; the unbiased form needs 2 or more.
biasedseries booltruetrue divides by length (population). false divides by length - 1 (sample).

Returns

series float: the standard deviation of the window, in the units of source.

Remarks

  • The result is in the same units as source, so a stdev of close is in price units.

Example

Pine ScriptVolatility of returnsOpen in editor
//@version=6
indicator("Return volatility")
ret = ta.change(close) / close[1] * 100
plot(ta.stdev(ret, 20), "Stdev of % change", color = color.red)

See also

Runs on Sidechair