Sidechair

array.stdev()

Browse the reference

Returns the standard deviation of the numbers in an array, in the same unit as the numbers.

Try it in the editor

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

Pine Script
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 int

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array to measure the spread of. na items are skipped.
biasedseries booltruetrue 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

Pine ScriptBands around a rolling meanOpen in editor
//@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