Returns the square root of a number; na for a negative number.
math.sqrt gives the non-negative number that multiplied by itself equals the input. It is the same as math.pow(x, 0.5).
Volatility measures scale with the square root of time, so math.sqrt is common in annualising: stdev * math.sqrt(252).
Syntax
math.sqrt(number: simple int/float) -> simple float
math.sqrt(number: input int/float) -> input float
math.sqrt(number: const int/float) -> const float
math.sqrt(number: series int/float) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | const/ | required | The number to take the root of. |
Returns
const/input/simple/series float: the square root, or na for negative input.
Remarks
math.sqrt(0)is 0.
Example
//@version=6
indicator("Annualised volatility")
logRet = math.log(close / close[1])
plot(ta.stdev(logRet, 20) * math.sqrt(252) * 100, "Vol %", color = color.red)See also
Runs on Sidechair