Returns how widely the numbers in an array spread around their mean, as the average squared distance.
By default it divides by the number of items, which treats the array as the whole population. Pass biased = false to divide by one less, the sample estimate.
na items are skipped. With a single number the sample form has nothing to divide by and returns na.
Syntax
array.variance(id: array<int/float>, biased: series bool (optional)) -> series float
array.variance(id: array<int>, biased: series bool (optional)) -> series int
array.variance(biased: series bool (optional)) -> series float
array.variance(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 variance of the numbers.
Remarks
- The square root of the variance is
array.stdev().
Example
//@version=6
indicator("array.variance: both forms", overlay = false)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 10
array.shift(win)
plot(array.variance(win), "Population")
plot(array.variance(win, false), "Sample", color.orange)See also
Runs on Sidechair