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
SQUARE(a)Parameters
| Name | Type | Description |
|---|---|---|
a | number | The value or expression to square. Any real input is valid. |
Formula
SQUARE(x) = x * xSQUARE(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)
// 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)
// 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)
// 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
ENDIFComparing 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.
SQUAREremoves sign.SQUARE(-4)andSQUARE(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)matchesPOW(x, 2). To undo it, useSQRTon the non-negative result.
Related instructions
SQRT, square root, the inverse ofSQUAREfor non-negative inputs.Pow, raises a base to a power, soPOW(x, 2)matchesSQUARE.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.
