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

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.