FLOOR
FLOOR in ProBuilder rounds a number down to the nearest integer, or to a set number of decimal places. Syntax, optional digits parameter and examples.
Syntax
floor(var, digits)Parameters
| Name | Type | Description |
|---|---|---|
var | number | The value to round down. |
digits | integer | Optional. Number of decimal places to round down to. When omitted, var is rounded down to the nearest whole integer. |
Formula
FLOOR(x) = largest integer <= xWith digits, the value is scaled by 10^digits, rounded down, then scaled back, so floor(x, d) rounds x down to d decimal places.
How it works
FLOOR always rounds toward negative infinity, discarding any fractional part for positive numbers. floor(3.1) and floor(3.9) both return 3. For negatives it moves away from zero: floor(-3.2) returns -4, the largest integer that is not greater than -3.2.
The optional digits argument sets the precision. floor(3.756, 1) returns 3.7. This is the mirror of CEIL, which always rounds up, and differs from ROUND, which picks the nearest value in either direction.
Examples
Example 1, Round an average down to whole units (Indicator)
// Whole-number floor of a moving average
ma = Average[20](close)
downTicks = floor(ma)
RETURN downTicks AS "MA rounded down"The fractional part of the average is dropped, so the plotted line sits at or below the raw average.
Example 2, Bucket a ratio into lower steps (ProScreener)
// Group price-to-average ratio into 0.1 lower buckets
ratio = close / Average[50](close)
bucket = floor(ratio, 1)
SCREENER[ratio < 1](bucket AS "Ratio floor")Rounding down to one decimal groups instruments into coarse bands anchored at each band's floor.
Example 3, Conservative position size (ProOrder)
// Round required contracts down so exposure never overshoots the budget
budget = 10000
priceValue = close
rawQty = budget / priceValue
qty = floor(rawQty)
IF qty >= 1 AND NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN
BUY qty CONTRACT AT MARKET
ENDIFRounding the raw quantity down keeps total exposure within the budget. For rounding an order price down to a valid tick, use ROUNDEDDOWN instead.
Common errors and gotchas
- Always rounds down, not toward the nearest.
floor(3.9)is3, not4. For the nearest integer useROUND; to round up useCEIL. - Negatives move away from zero.
floor(-2.5)returns-3, not-2, because -3 is the largest integer that is not greater than -2.5. - Not the same as ROUNDEDDOWN.
FLOORrounds down to integers or decimals.ROUNDEDDOWNrounds an order price down to the nearest valid tick of the instrument.
Related instructions
CEIL, rounds up to the nearest integer or decimal, the opposite direction.ROUND, rounds to the nearest integer or decimal.ROUNDEDDOWN, rounds an order price down to the nearest tradable tick.ROUNDEDUP, rounds an order price up 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.
