Returns the standard deviation of the numbers in an array, in the same unit as the numbers.
It is the square root of array.variance(). With the default biased = true the divisor is the item count; with biased = false it is the count minus one.
Items that are na are skipped, so a gap does not break the calculation. The result matches ta.stdev() when the array holds the latest N values of a series.
Syntax
array.stdev(id: array<int/float>, biased: series bool (optional)) -> series float
array.stdev(id: array<int>, biased: series bool (optional)) -> series int
array.stdev(biased: series bool (optional)) -> series float
array.stdev(biased: series bool (optional)) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to measure the spread of. na items are skipped. |
| biased | series bool | true | true divides by the count (population); false divides by the count minus one (sample). |
Returns
series float or series int: The standard deviation of the numbers.
Example
//@version=6
indicator("array.stdev: bands", overlay = true)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 20
array.shift(win)
mid = array.avg(win)
dev = array.stdev(win)
plot(mid, "Mean")
plot(mid + 2 * dev, "Upper", color.green)
plot(mid - 2 * dev, "Lower", color.red)See also
Runs on Sidechair