Mathematical/probuilder · probacktest · proorder · proscreener

SQRT

SQRT in ProBuilder returns the square root of a non-negative number. The domain limit, syntax, the link to SQUARE and Pow, and worked trading examples.

Syntax

probuilder
SQRT(a)

Parameters

NameTypeDescription
anumberA non-negative value or expression. Negative inputs are undefined and raise an error.

Formula

code
SQRT(x) = x^(1/2),   defined for x >= 0

SQRT(0) returns 0, SQRT(16) returns 4, and SQRT(2) returns roughly 1.41421. The result is always non-negative.

How it works

SQRT returns the non-negative number whose square equals the input. It equals POW(x, 0.5) and undoes SQUARE for non-negative values. The input must be non-negative; a negative argument has no real square root and raises an error, so guard the input when it can go below zero, for example with SQRT(MAX(x, 0)).

In trading, square roots appear when converting variance to standard deviation, scaling volatility by time (the square-root-of-time rule), or normalizing distances.

Examples

Example 1, Square root of a value (Indicator)

probuilder
// Square root of 16
variable1 = 16
root = SQRT(variable1)
RETURN root AS "SQRT(16)"

SQRT(16) returns 4, the non-negative number that squares back to 16.

Example 2, Scale volatility by time (ProScreener)

probuilder
// Project one-bar volatility over a 10-bar horizon
barVol = STD[20](close)
projected = barVol * SQRT(10)
SCREENER[projected > 0](projected AS "10-bar vol")

Multiplying by SQRT(10) applies the square-root-of-time rule to scale a per-bar volatility figure to a longer horizon.

Example 3, Distance normalized by a square root (ProOrder)

probuilder
// Guard against negative input before taking the root
raw = close - Average[50](close)
dist = SQRT(MAX(raw * raw, 0))
IF dist < close * 0.02 AND NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

Squaring the difference first guarantees a non-negative input, and MAX(..., 0) is a defensive belt-and-braces guard so SQRT never sees a negative value.

Common errors and gotchas

  • Input must be non-negative. SQRT of a negative value is undefined and raises an error. Guard with SQRT(MAX(x, 0)) or square the input first when it can go below zero.
  • Returns the non-negative root only. SQRT(16) is 4, not -4. The function never returns the negative root.
  • Equivalent to POW(x, 0.5). SQRT(x) and POW(x, 0.5) give the same result and share the same domain limit.
  • SQUARE, squares a value, the inverse of SQRT for non-negative inputs.
  • Pow, raises a base to a power, so POW(x, 0.5) matches SQRT.
  • ABS, absolute value, useful to force a non-negative input.
  • EXP, exponential function.
  • LOG, natural logarithm.
  • STD, standard deviation, built on the square root of variance.
  • Volatility, volatility measure related to SQRT scaling.