ta.stdev() - Pine Script Function
ta.stdev()
Section titled “ta.stdev()”Overview
Section titled “Overview”source (series int/float) Series of values to process.
Syntax
Section titled “Syntax”ta.stdev(source, length, biased) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
Returns
Section titled “Returns”Standard deviation.
Remarks
Section titled “Remarks”- If biased is true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("ta.stdev")plot(ta.stdev(close, 5))//the same on pineisZero(val, eps) => math.abs(val) <= epsSUM(fst, snd) => EPS = 1e-10 res = fst + sndif isZero(res, EPS) res := 0elseif notisZero(res, 1e-4) res := reselse 15pine_stdev(src, length) => avg = ta.sma(src, length) sumOfSquareDeviations = 0.0for i = 0 to length - 1 sum =SUM(src[i], -avg) sumOfSquareDeviations := sumOfSquareDeviations + sum * sum stdev = math.sqrt(sumOfSquareDeviations / length)plot(pine_stdev(close, 5))