ROUND
ROUND in ProBuilder rounds a number to the nearest integer, or to a set number of decimal places. Syntax, the banker's rounding note and worked examples.
Syntax
ROUND(a, digits)Parameters
| Name | Type | Description |
|---|---|---|
a | number | The value to round. |
digits | integer | Optional. Number of decimal places to round to. When omitted, a is rounded to the nearest whole number. |
Formula
ROUND(x) = nearest integer to x, halves rounded to the nearest even valueWith digits, a is rounded to that many decimal places, so ROUND(3.14159, 2) returns 3.14.
How it works
ROUND chooses the nearest value in either direction, unlike CEIL which always rounds up and FLOOR which always rounds down. A fractional part below 0.5 rounds down, above 0.5 rounds up. Exact halves follow banker's rounding: they go to the nearest even number, so ROUND(2.5) gives 2 and ROUND(3.5) gives 4. This reduces cumulative bias when rounding many values.
The optional digits argument sets the precision of the result, useful for normalizing prices or indicator readings to a fixed number of decimals.
Examples
Example 1, Round a rate of change (Indicator)
// Round the 10-period rate of change to a whole number
i1 = ROC[10](close)
roundedROCvalue = ROUND(i1)
RETURN i1 AS "ROC", roundedROCvalue AS "ROC rounded"If the raw reading is 9.6, ROUND returns 10. A reading of 9.4 would round down to 9.
Example 2, Round to two decimals for grouping (ProScreener)
// Group instruments by a two-decimal ratio
ratio = close / Average[50](close)
r = ROUND(ratio, 2)
SCREENER[r >= 1](r AS "Ratio 2dp")Rounding to two decimals collapses near-identical ratios into shared buckets.
Example 3, Round a computed target price (ProOrder)
// Round a target price to a whole number before display
entry = close
target = ROUND(entry * 1.015)
IF NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIFROUND normalizes the computed target to a whole number. To snap an order price to a valid tick instead, use ROUNDEDUP or ROUNDEDDOWN.
Common errors and gotchas
- Halves round to even.
ROUND(2.5)returns 2, not 3, because banker's rounding sends exact halves to the nearest even number. Do not assume 0.5 always rounds up. - Rounds both directions. Unlike
CEILandFLOOR,ROUNDcan go up or down. UseCEILto force upward andFLOORto force downward. - Not tick rounding.
ROUNDworks on integers and decimals. To round an order price to the instrument's tradable tick, useROUNDEDUPorROUNDEDDOWN.
Related instructions
CEIL, rounds up to the nearest integer or decimal.FLOOR, rounds down to the nearest integer or decimal.ROUNDEDUP, rounds an order price up to the nearest tradable tick.ROUNDEDDOWN, rounds an order price down to the nearest tradable tick.ABS, absolute value, often paired with rounding.SGN, sign of a value.MOD, remainder of a division.
