Mathematical/probuilder · probacktest · proorder · proscreener

SQUARE

SQUARE in ProBuilder returns the square of a number, the value multiplied by itself. Syntax, the inverse link to SQRT and Pow, and worked trading examples.

Syntax

probuilder
SQUARE(a)

Parameters

NameTypeDescription
anumberThe value or expression to square. Any real input is valid.

Formula

code
SQUARE(x) = x * x

SQUARE(5) is 25, SQUARE(-4) is 16, and SQUARE(0) is 0. The result is always zero or positive.

How it works

SQUARE multiplies its argument by itself. Because a negative times a negative is positive, the output is always non-negative, which makes SQUARE a way to strip sign while also amplifying large values. It equals POW(x, 2) and undoes SQRT for non-negative inputs.

Squaring appears throughout statistics: variance is the mean of squared deviations, and squared distances weight large moves more heavily than small ones, which is useful for penalizing outliers.

Examples

Example 1, Square a value (Indicator)

probuilder
// Square of 5
variable1 = 5
result = SQUARE(variable1)   // 25
RETURN result AS "SQUARE(5)"

The function multiplies 5 by itself, returning 25.

Example 2, Squared deviation from the mean (ProScreener)

probuilder
// Emphasize instruments stretched far from their average
dev = close - Average[50](close)
sq = SQUARE(dev)
SCREENER[sq > 0](sq AS "Squared deviation")

Squaring the deviation removes its sign and grows quickly with distance, so instruments far from their average stand out.

Example 3, Squared distance filter (ProOrder)

probuilder
// Enter only when price sits close to its average, measured by squared distance
dev = close - Average[20](close)
sqDist = SQUARE(dev)
threshold = SQUARE(close * 0.01)
IF sqDist < threshold AND NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

Comparing squared distance against a squared threshold avoids a square root while keeping the test symmetric around the average.

Common errors and gotchas

  • Output is always non-negative. SQUARE removes sign. SQUARE(-4) and SQUARE(4) both return 16, so a squared value cannot tell you the original direction.
  • Grows fast. Squaring amplifies large inputs sharply, which is deliberate for weighting outliers but can distort scans if not intended.
  • Equivalent to POW(x, 2). SQUARE(x) matches POW(x, 2). To undo it, use SQRT on the non-negative result.
  • SQRT, square root, the inverse of SQUARE for non-negative inputs.
  • Pow, raises a base to a power, so POW(x, 2) matches SQUARE.
  • ABS, absolute value, another sign-removing operation that keeps scale.
  • EXP, exponential function.
  • STD, standard deviation, built on squared deviations.
  • Variation, percentage change between bars.
  • Volatility, volatility measure related to squared moves.