Returns the standard deviation of source over the last length bars, dividing by length unless biased is false.
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
ta.stdev(source: series int/float, length: series int, biased: series bool (optional)) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | The series whose spread around its own mean is measured over length bars. |
| length | series int | required | Number of bars in the window. A whole number of 1 or more; the unbiased form needs 2 or more. |
| biased | series bool | true | true 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
//@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