Mathematical/probuilder · probacktest · proorder · proscreener

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

probuilder
ceil(var, digits)

Parameters

NameTypeDescription
varnumberThe value to round up.
digitsintegerOptional. Number of decimal places to round up to. When omitted, var is rounded up to the nearest whole integer.

Formula

code
CEIL(x) = smallest integer >= x

With 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)

probuilder
// 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)

probuilder
// 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)

probuilder
// 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
ENDIF

Rounding 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) is 4, not 3. If you want the nearest integer, use ROUND; to round down, use FLOOR.
  • 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. CEIL rounds up to integers or decimals. ROUNDEDUP rounds an order price up to the nearest valid tick of the instrument.
  • 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.