Returns the variance of source over the last length bars: the mean squared distance from the window's average.
ta.variance takes the mean of the window, squares each value's distance from it and averages those squares. With biased = true the divisor is length; with false it is length - 1.
The result is in squared units of source and equals ta.stdev(source, length, biased) squared. Early bars, before the window fills, return na.
Syntax
ta.variance(source: series int/float, length: series int, biased: series bool (optional)) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | The series whose squared 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 variance of the window, or na while it is not full.
Remarks
- Variance of a constant series is 0.
Example
//@version=6
indicator("Variance")
plot(ta.variance(close, 20), "Variance", color = color.purple)
plot(math.pow(ta.stdev(close, 20), 2), "Stdev squared", color = color.orange)See also
Runs on Sidechair