ta.stdev()
Standard Deviation
Standard deviation measures the dispersion of a dataset relative to its mean.
Syntax
ta.stdev(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. 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
//@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.
Related Pine Script Functions
ta.variance() - Variance
Learn how to use ta.variance() in Pine Script. Calculate statistical variance for volatility analysis.
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.
ta.bbw() - Bollinger Bands Width
Learn how to use ta.bbw() in Pine Script. Syntax, parameters, code examples for measuring Bollinger Band squeeze and width.
ta.atr() - Average True Range
Learn how to use ta.atr() in Pine Script. Syntax, parameters, code examples for the Average True Range volatility indicator.