Sidechair

math.ceil()

Browse the reference

Rounds a number up to the next whole number; a number that is already whole stays as it is.

Try it in the editor

math.ceil rounds up: 2.1 gives 3 and -2.9 gives -2. A value that is already whole stays as it is.

Use it to size things in whole units, such as the number of bars needed to cover a duration.

Syntax

Pine Script
math.ceil(number: simple int/float) -> simple int
math.ceil(number: input int/float) -> input int
math.ceil(number: const int/float) -> const int
math.ceil(number: series int/float) -> series int

Arguments

NameTypeDefaultDescription
numberconst/input/simple/series int/floatrequiredThe number to round up to the next whole number. A whole number stays as it is.

Returns

const/input/simple/series int: the whole number at or above the input.

Remarks

Example

Pine ScriptRound the high up to the next dollarOpen in editor
//@version=6
indicator("Ceiling", overlay = true)
plot(math.ceil(high), "Ceiling of high", color = color.red, style = plot.style_stepline)
plot(math.floor(low), "Floor of low", color = color.green, style = plot.style_stepline)

See also

Runs on Sidechair