ABS
ABS in ProBuilder returns the absolute value of a number, its magnitude without sign, so a negative input becomes positive. Syntax, parameters and examples.
Syntax
ABS(expression)Parameters
| Name | Type | Description |
|---|---|---|
expression | number | The numeric value or formula whose absolute value is returned. Can be a constant, a variable, or a full expression. |
Formula
ABS(x) = |x|For any input, ABS returns a value that is zero or positive. A positive input passes through unchanged, a negative input has its sign flipped, and zero returns zero.
How it works
On every bar ABS evaluates its argument and strips the sign. It is a pure function with no lookback and no memory, so ABS(close - open) gives the size of the current bar's body regardless of whether the bar closed up or down. This makes it the standard tool for measuring distances, gaps and deviations where direction is not the point.
ABS pairs naturally with SGN, which returns the sign as -1, 0 or 1. Together they split a value into magnitude and direction: value = SGN(value) * ABS(value).
Examples
Example 1, Size of the current bar body (Indicator)
// Absolute distance between open and close, regardless of direction
bodySize = ABS(close - open)
RETURN bodySize AS "Body size"The subtraction is negative on down bars and positive on up bars. Wrapping it in ABS returns the magnitude either way, so the plotted series is always zero or positive.
Example 2, Large single-bar moves (ProScreener)
// Instruments whose last bar moved more than 2% in either direction
pct = ABS(close - close[1]) / close[1] * 100
SCREENER[pct > 2](pct AS "Abs move %")Using ABS makes the scan symmetric: a 2% drop and a 2% rise both qualify. Without it the condition would only catch moves in one direction.
Example 3, Distance-based stop guard (ProOrder)
// Block new entries when price sits far from its average
ma = Average[50](close)
gap = ABS(close - ma)
IF gap < close * 0.01 THEN
IF NOT LongOnMarket AND close CROSSES OVER ma THEN
BUY 1 CONTRACT AT MARKET
ENDIF
ENDIFABS(close - ma) measures how far price has stretched from the moving average without caring which side it is on, so a single threshold covers both stretched-above and stretched-below cases.
Common errors and gotchas
- It only changes negatives.
ABSnever makes a value smaller in magnitude and never returns a negative. Applying it to an already positive series has no effect and can hide a sign you actually needed. - Magnitude discards direction. After
ABSyou cannot tell whether the original value was up or down. Keep the raw value, or useSGN, if the sign matters later. - Not a rounding function.
ABS(-3.7)is3.7, not4. For rounding useROUND,CEILorFLOOR.
Related instructions
SGN, returns the sign of a value as -1, 0 or 1, the direction thatABSdiscards.SQRT, square root, defined only for non-negative inputs thatABScan supply.SQUARE, squares a value, another way to remove sign at the cost of scale.MAX, larger of two values, useful withABSto clamp distances.MIN, smaller of two values.ROUND, rounds to the nearest integer or decimal, unlikeABS.Momentum, raw price change that is often wrapped inABSto measure size.Variation, percentage change between bars.
