Sidechair

math.sqrt()

Browse the reference

Returns the square root of a number; na for a negative number.

Try it in the editor

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

Pine Script
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 float

Arguments

NameTypeDefaultDescription
numberconst/input/simple/series int/floatrequiredThe 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

Pine ScriptAnnualised volatilityOpen in editor
//@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