StatisticalPine Script v6

ta.variance()Variance

Variance is the square of the standard deviation. It measures how far a set of numbers are spread out from their average value.

Syntax

Syntax
ta.variance(source, length, biased) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars in the rolling window.
biasedseries boolOptional. Population vs sample variance divisor; default true.

Returns

Variance of source for length bars back.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.variance")
plot(ta.variance(close, 20, true))

// Relationship to stdev
plot(math.sqrt(ta.variance(close, 20, true)))
plot(ta.stdev(close, 20, true))

Trading Applications

Measure price dispersion for volatility analysis

Build custom volatility indicators

Calculate risk metrics for portfolio management

Use as input for statistical trading models

Related Functions

ta.stdevta.dev

Frequently Asked Questions

ta.variance() computes rolling variance of the source over length bars (average squared deviation from the rolling mean), after ignoring na values.

Standard deviation is the square root of variance. In Pine, ta.stdev() and ta.variance() are consistent when using the same biased flag and length.

When biased is true (default), variance uses a population-style divisor on the non-na count; when false, it behaves like a sample variance with a different normalization. Match this flag to ta.stdev() for consistency.

Generate ta.variance() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.variance() and other built-in functions instantly.