VolatilityPine Script v6

ta.stdev()Standard Deviation

Standard deviation measures the dispersion of a dataset relative to its mean.

Syntax

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

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars in the rolling window.
biasedseries boolOptional. If true, uses population-style divisor; default true.

Returns

Standard deviation.

Remarks

na values in the source series are ignored; the function calculates on the length quantity of non-na values.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.stdev")
plot(ta.stdev(close, 5))

//the same on pine
pine_stdev(src, length) =>
    avg = ta.sma(src, length)
    sumOfSquareDeviations = 0.0
    for i = 0 to length - 1
        sum = math.pow(src[i] - avg, 2)
        sumOfSquareDeviations := sumOfSquareDeviations + sum
    math.sqrt(sumOfSquareDeviations / length)
plot(pine_stdev(close, 5))

Trading Applications

Measure price volatility over a given period

Build custom Bollinger Bands with different multipliers

Identify unusual price movements (outliers)

Create volatility-based position sizing rules

Related Functions

Frequently Asked Questions

ta.stdev() computes rolling standard deviation of the source over length bars, measuring how spread out values are around the rolling mean. It is commonly used in volatility channels and risk models.

Biased (population) variance divides by n; unbiased (sample) variance divides by n−1. Pine defaults biased to true for ta.stdev(); switch when you need sample standard deviation for statistical consistency.

Common uses include band indicators (distance from mean in σ units), volatility filters (trade only when stdev is above/below a threshold), and position sizing scaled to recent dispersion.

Generate ta.stdev() Code with AI

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