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
ta.variance(source, length, biased) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | series int | Number of bars in the rolling window. |
| biased | series bool | Optional. 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
//@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
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.
Related Pine Script Functions
ta.stdev() - Standard Deviation
Learn how to use ta.stdev() in Pine Script. Syntax, parameters, code examples for statistical standard deviation calculation.
ta.correlation() - Correlation
Learn how to use ta.correlation() in Pine Script. Calculate correlation coefficient between two series.
ta.percentrank() - Percent Rank
Learn how to use ta.percentrank() in Pine Script. Calculate percentile ranking of current value.
ta.bb() - Bollinger Bands
Learn how to use ta.bb() in Pine Script. Syntax, parameters, code examples for Bollinger Bands with upper, middle, and lower bands.