CEIL
CEIL in ProBuilder rounds a number up to the nearest integer, or to a set number of decimal places. Syntax, the optional digits parameter and examples.
Syntax
ceil(var, digits)Parameters
| Name | Type | Description |
|---|---|---|
var | number | The value to round up. |
digits | integer | Optional. Number of decimal places to round up to. When omitted, var is rounded up to the nearest whole integer. |
Formula
CEIL(x) = smallest integer >= xWith digits, the value is scaled by 10^digits, rounded up, then scaled back, so ceil(x, d) rounds x up to d decimal places.
How it works
CEIL always rounds toward positive infinity, never toward zero. ceil(3.1) and ceil(3.9) both return 4 because any fractional part pushes the result up. For negatives it moves toward zero: ceil(-3.7) returns -3, the smallest integer that is not less than -3.7.
The optional digits argument lets you round up at a chosen precision. ceil(3.14159, 2) returns 3.15. This differs from ROUND, which chooses the nearest value in either direction, and from FLOOR, which always rounds down.
Examples
Example 1, Round an average up to whole units (Indicator)
// Whole-number ceiling of a moving average
ma = Average[20](close)
upTicks = ceil(ma)
RETURN upTicks AS "MA rounded up"Any fractional part of the average is pushed up to the next integer, so the plotted line sits at or above the raw average.
Example 2, Bucket a ratio into upper steps (ProScreener)
// Group price-to-average ratio into 0.1 upper buckets
ratio = close / Average[50](close)
bucket = ceil(ratio, 1)
SCREENER[ratio > 1](bucket AS "Ratio ceiling")Rounding up to one decimal groups instruments into coarse bands while keeping each band's ceiling.
Example 3, Position size that covers a target (ProOrder)
// Round required contracts up so exposure is never short of target
targetExposure = 10000
priceValue = close
rawQty = targetExposure / priceValue
qty = ceil(rawQty)
IF NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
BUY qty CONTRACT AT MARKET
ENDIFRounding the raw quantity up ensures the filled size covers the target exposure rather than falling just under it. For rounding an order price to a valid tick, use ROUNDEDUP instead.
Common errors and gotchas
- Always rounds up, not toward the nearest.
ceil(3.1)is4, not3. If you want the nearest integer, useROUND; to round down, useFLOOR. - Negatives move toward zero.
ceil(-2.5)returns-2, not-3, because -2 is the smallest integer that is at least -2.5. - Not the same as ROUNDEDUP.
CEILrounds up to integers or decimals.ROUNDEDUProunds an order price up to the nearest valid tick of the instrument.
Related instructions
FLOOR, rounds down to the nearest integer or decimal, the opposite direction.ROUND, rounds 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 combined with rounding.SGN, sign of a value.MOD, remainder of a division, another integer-oriented operation.
