math.* reference

24 scalar helpers that apply per bar. They take numeric values (which can be per-bar series expressions like close - open) and return a number.

Constants

math.pi3.14159…π — ratio of a circle’s circumference to its diameter.
math.e2.71828…Euler’s number, the base of the natural logarithm.
math.phi1.61803…The golden ratio, (1 + √5) / 2.

Functions

math.abs

math.abs(x) → number

Absolute value of x.

xnumberAny value.

Returns: number

PulseScript
pulse 1
draw line(math.abs(close - open), title: "candle body")

math.sign

math.sign(x) → number

Sign of x: -1, 0, or 1.

xnumberAny value.

Returns: number (-1 | 0 | 1)

PulseScript
pulse 1
draw line(math.sign(close - open), title: "bar direction")

math.floor

math.floor(x) → number

Largest integer ≤ x.

xnumberAny value.

Returns: number

PulseScript
pulse 1
draw line(math.floor(close), title: "floor(close)")

math.ceil

math.ceil(x) → number

Smallest integer ≥ x.

xnumberAny value.

Returns: number

PulseScript
pulse 1
draw line(math.ceil(close), title: "ceil(close)")

math.round

math.round(x, decimals?) → number

Round x to the nearest integer, or to `decimals` places.

xnumberValue to round.
decimalsnumber?Decimal places (0–12). Omitted = nearest integer.

Returns: number

PulseScript
pulse 1
draw line(math.round(close, 2), title: "close rounded")

math.sqrt

math.sqrt(x) → number

Square root of x.

xnumberNon-negative value.

Returns: number

PulseScript
pulse 1
draw line(math.sqrt(volume), title: "sqrt(volume)")

math.exp

math.exp(x) → number

e raised to the power x.

xnumberExponent.

Returns: number

PulseScript
pulse 1
draw line(math.exp(close / open - 1), title: "exp(return)")

math.log

math.log(x) → number

Natural logarithm (base e) of x.

xnumberPositive value.

Returns: number

PulseScript
pulse 1
draw line(math.log(close), title: "ln(close)")

math.log10

math.log10(x) → number

Base-10 logarithm of x.

xnumberPositive value.

Returns: number

PulseScript
pulse 1
draw line(math.log10(volume), title: "log10(volume)")

math.pow

math.pow(base, exp) → number

base raised to the power exp.

basenumberBase.
expnumberExponent.

Returns: number

PulseScript
pulse 1
draw line(math.pow(close / open, 2), title: "ratio squared")

math.sin

math.sin(x) → number

Sine of x (x in radians).

xnumberAngle in radians.

Returns: number

PulseScript
pulse 1
draw line(math.sin(barIndex / 10), title: "sine wave")

math.cos

math.cos(x) → number

Cosine of x (x in radians).

xnumberAngle in radians.

Returns: number

PulseScript
pulse 1
draw line(math.cos(barIndex / 10), title: "cosine wave")

math.tan

math.tan(x) → number

Tangent of x (x in radians).

xnumberAngle in radians.

Returns: number

PulseScript
pulse 1
draw line(math.tan(barIndex / 100), title: "tan")

math.asin

math.asin(x) → number

Arcsine of x, in radians (x in [-1, 1]).

xnumberValue in [-1, 1].

Returns: number (radians)

PulseScript
pulse 1
draw line(math.asin(math.sin(barIndex / 10)), title: "asin")

math.acos

math.acos(x) → number

Arccosine of x, in radians (x in [-1, 1]).

xnumberValue in [-1, 1].

Returns: number (radians)

PulseScript
pulse 1
draw line(math.acos(math.cos(barIndex / 10)), title: "acos")

math.atan

math.atan(x) → number

Arctangent of x, in radians.

xnumberAny value.

Returns: number (radians)

PulseScript
pulse 1
draw line(math.atan(close - open), title: "atan(body)")

math.atan2

math.atan2(y, x) → number

Angle (radians) of the vector (x, y) — full quadrant.

ynumberY component.
xnumberX component.

Returns: number (radians)

PulseScript
pulse 1
draw line(math.atan2(high - low, close), title: "atan2")

math.toDegrees

math.toDegrees(radians) → number

Convert radians to degrees.

radiansnumberAngle in radians.

Returns: number (degrees)

PulseScript
pulse 1
draw line(math.toDegrees(math.atan(close - open)), title: "slope°")

math.toRadians

math.toRadians(degrees) → number

Convert degrees to radians.

degreesnumberAngle in degrees.

Returns: number (radians)

PulseScript
pulse 1
draw line(math.toRadians(45), title: "45° in rad")

math.clamp

math.clamp(x, lo, hi) → number

Constrain x to the range [lo, hi].

xnumberValue to clamp.
lonumberLower bound.
hinumberUpper bound.

Returns: number

PulseScript
pulse 1
draw line(math.clamp(rsi(close, 14), 30, 70), title: "RSI clamped")

math.min

math.min(a, b, …) → number

Smallest of the given values.

a, b, …number…Two or more values.

Returns: number

PulseScript
pulse 1
draw line(math.min(open, close), title: "candle bottom body")

math.max

math.max(a, b, …) → number

Largest of the given values.

a, b, …number…Two or more values.

Returns: number

PulseScript
pulse 1
draw line(math.max(open, close), title: "candle top body")

math.sum

math.sum(a, b, …) → number

Sum of the given values (NOT a rolling window — see ta.sum for that).

a, b, …number…Values to add.

Returns: number

PulseScript
pulse 1
draw line(math.sum(open, high, low, close) / 4, title: "OHLC avg")

math.avg

math.avg(a, b, …) → number

Arithmetic mean of the given values.

a, b, …number…Values to average.

Returns: number

PulseScript
pulse 1
draw line(math.avg(high, low, close), title: "typical price")