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

Frequently Asked Questions

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.