Builtins: math

SignatureReturns
math.abs(x: float) -> floatAbsolute value
math.min(a: float, b: float) -> floatSmaller of exactly two values
math.max(a: float, b: float) -> floatLarger of exactly two values
math.round(x: float [, digits: int]) -> floatNearest whole number, or rounded to digits decimals, 0 through 15
math.round_to_tick(x: float) -> floatRounded to the instrument tick, nan when the chart states no tick
math.floor(x: float) -> floatRound down
math.ceil(x: float) -> floatRound up
math.sqrt(x: float) -> floatSquare root
math.pow(base: float, exponent: float) -> floatPower
math.log(x: float) -> floatNatural logarithm
math.exp(x: float) -> floatNatural exponential
math.sign(x: float) -> floatMinus one, zero or one
math.clamp(x: float, low: float, high: float) -> floatx held inside your own bounds
math.scale(x: float, in_min: float, in_max: float, out_min: float, out_max: float) -> floatx remapped from one range to another, clamped at both ends
math.avg(a: float, b: float, ... ) -> floatMean of 2 to 24 values
math.log10(x: float) -> floatBase 10 logarithm
math.sin, math.cos, math.tan(x: float) -> floatTrigonometry in radians
math.asin, math.acos, math.atan(x: float) -> floatThe inverse functions, in radians
math.todegrees(x: float) -> float, math.toradians(x: float) -> floatAngle conversion
math.pi, math.eThe constants, written without parentheses

math.min and math.max take exactly two arguments; nest them for more. An undefined domain, such as the square root of a negative number, returns nan.

math.log, math.log10, math.exp, math.pow and the trigonometry give the same result, to the last digit, on every device, so a script draws the same thing in the browser, in the desktop app and on the phone.

math.scale maps a size to a radius. It is clamped at both ends on purpose, so a print far above the top of your range keeps the largest radius instead of drawing a circle wider than the chart. It answers nan for a nan x, and when in_max is not above in_min it answers out_max at or above in_min and out_min below it.

let size: float = tape.largest_size()
let radius: float = math.scale(nz(size, 0), 25, 400, 5, 22)

Every layer of the market, Orderflow to optionflow, on one chart.

Institutional grade Orderflow data with backtesting and journaling built in. Join the waitlist for early access.

Get Access