Math

math.abs

Definition: The absolute value of number is number if number >= 0, or -number otherwise.

Syntax:

math.abs(number) β†’ simple int/float
math.abs(number) β†’ series int/float

Returns:

The absolute value of `number`.

Arguments:

NameTypeDescription

number

simple int/float

The number for which to calculate the absolute value.


math.acos

Definition: The acos function returns the arccosine (in radians) of number such that cos(acos(y)) = y for y in range [-1, 1].

Syntax:

math.acos(angle) β†’ simple float
math.acos(angle) β†’ series float

Returns:

The arc cosine of a value; the returned angle is in the range [0, Pi], or na if y is outside of range [-1, 1].

Arguments:

NameTypeDescription

angle

simple float

The angle in radians for which to calculate the arccosine.


math.asin

Definition: The asin function returns the arcsine (in radians) of number such that sin(asin(y)) = y for y in range [-1, 1].

Syntax:

math.asin(angle) β†’ simple float
math.asin(angle) β†’ series float

Returns:

The arcsine of a value; the returned angle is in the range [-Pi/2, Pi/2], or na if y is outside of range [-1, 1].

Arguments:

NameTypeDescription

angle

simple float

The angle in radians for which to calculate the arcsine.


math.atan

Definition: The atan function returns the arctangent (in radians) of number such that tan(atan(y)) = y for any y.

Syntax:

math.atan(angle) β†’ simple float
math.atan(angle) β†’ series float

Returns:

The arc tangent of a value; the returned angle is in the range [-Pi/2, Pi/2].

Arguments:

NameTypeDescription

angle

simple float

The angle in radians for which to calculate the arctangent.


math.avg

Definition: Calculates the average of all given series (elementwise).

Syntax:

math.avg(number0, number1, ...) β†’ simple float
math.avg(number0, number1, ...) β†’ series float

Returns:

The average value.

Arguments:

NameTypeDescription

number0, number1, ...

series float

The series of numbers to calculate the average of. Multiple series can be provided.


math.ceil

Definition: Returns the smallest integer greater than or equal to the argument.

Syntax:

math.ceil(number) β†’ simple int
math.ceil(number) β†’ series int

Returns:

The smallest integer greater than or equal to the given number.

Arguments:

NameTypeDescription

number

series float

The number to ceil.


math.cos

Definition: Returns the trigonometric cosine of an angle.

Syntax:

math.cos(angle) β†’ simple float
math.cos(angle) β†’ series float

Returns:

The trigonometric cosine of an angle.

Arguments:

NameTypeDescription

angle

series float

The angle in radians.


math.exp

Definition: Returns the value of Euler's number raised to the power of the given number.

Syntax:

math.exp(number) β†’ simple float
math.exp(number) β†’ series float

Returns:

The value of Euler's number raised to the power of the given number.

Arguments:

NameTypeDescription

number

series float

The number for which to calculate the exponent.


math.floor

Definition: Returns the largest integer less than or equal to the given number.

Syntax:

math.floor(number) β†’ simple int
math.floor(number) β†’ series int

Returns:

The largest integer less than or equal to the given number.

Arguments:

NameTypeDescription

number

series int

The number for which to calculate the floor value.

math.log

Definition: Returns the natural logarithm of any number greater than 0.

Syntax:

math.log(number) β†’ simple float
math.log(number) β†’ series float

Returns:

The natural logarithm of the given number.

Arguments:

NameTypeDescription

number

series float

The number for which to calculate the natural logarithm.


math.log10

Definition: Returns the base 10 logarithm of a number.

Syntax:

math.log10(number) β†’ simple float
math.log10(number) β†’ series float

Returns:

The base 10 logarithm of the given number.

Arguments:

NameTypeDescription

number

series float

The number for which to calculate the base 10 logarithm.


math.max

Definition: Returns the greatest of multiple values.

Syntax:

math.max(number0, number1, ...) β†’ simple int/float
math.max(number0, number1, ...) β†’ input int/float
math.max(number0, number1, ...) β†’ series int/float

Returns:

The greatest of the given values.

Arguments:

NameTypeDescription

number0, number1, ...

series int/float

The values to compare and find the greatest among them.


math.min

Definition: Returns the smallest of multiple values.

Syntax:

math.min(number0, number1, ...) β†’ simple int/float
math.min(number0, number1, ...) β†’ input int/float
math.min(number0, number1, ...) β†’ series int/float

Returns:

The smallest of the given values.

Arguments:

NameTypeDescription

number0, number1, ...

series int/float

The values to compare and find the smallest among them.


math.pow

Definition: Mathematical power function.

Syntax:

math.pow(base, exponent) β†’ simple float
math.pow(base, exponent) β†’ series float

Returns:

`base` raised to the power of `exponent`. If `base` is a series, it is calculated elementwise.

Arguments:

NameTypeDescription

base

series int/float

Specify the base to use.

exponent

series int/float

Specifies the exponent.


math.random

Definition: Returns a pseudo-random value. The function will generate a different sequence of values for each script execution. Using the same value for the optional seed argument will produce a repeatable sequence.

Syntax:

math.random(min, max, seed) β†’ series float

Arguments:

NameTypeDescription

min

series int/float

The lower bound of the range of random values. The value is not included in the range. The default is 0.

max

series int/float

The upper bound of the range of random values. The value is not included in the range. The default is 1.

seed

series int

Optional argument. When the same seed is used, allows successive calls to the function to produce a repeatable set of values.

Returns:

A random value.

math.round

Definition: Returns the value of number rounded to the nearest integer, with ties rounding up. If the precision parameter is used, returns a float value rounded to that amount of decimal places.

Syntax:

math.round(number) β†’ simple int
math.round(number) β†’ series int
math.round(number, precision) β†’ simple float
math.round(number, precision) β†’ series float

Returns:

The value of `number` rounded to the nearest integer, or according to precision.

Arguments:

NameTypeDescription

number

series int/float

The value to be rounded.

precision

series int

Optional argument. Decimal places to which number will be rounded. When no argument is supplied, rounding is to the nearest integer.


math.sign

Definition: Sign (signum) of number is zero if number is zero, 1.0 if number is greater than zero, -1.0 if number is less than zero.

Syntax:

math.sign(number) β†’ simple float
math.sign(number) β†’ series float

Returns:

The sign of the argument.

Arguments:

NameTypeDescription

number

series int/float

The number for which to determine the sign.


math.sin

Definition: The sin function returns the trigonometric sine of an angle.

Syntax:

math.sin(angle) β†’ simple float
math.sin(angle) β†’ series float

Returns:

The trigonometric sine of an angle.

Arguments:

NameTypeDescription

angle

series int/float

Angle, in radians.


math.sqrt

Definition: Square root of any number >= 0 is the unique y >= 0 such that y^2 = number.

Syntax:

math.sqrt(number) β†’ simple float
math.sqrt(number) β†’ series float

Returns:

The square root of `number`.

Arguments:

NameTypeDescription

number

series int/float

The number to calculate the square root of. It must be greater than or equal to 0.


math.sum

Definition: The sum function returns the sliding sum of last y values of x.

Syntax:

math.sum(source, length) β†’ series float

Arguments:

NameTypeDescription

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

Returns:

Sum of `source` for `length` bars back.

math.tan

Definition: The tan function returns the trigonometric tangent of an angle.

Syntax:

math.tan(angle) β†’ simple float
math.tan(angle) β†’ series float

Returns:

The trigonometric tangent of an angle.

Arguments:

NameTypeDescription

angle

series int/float

Angle, in radians.


math.todegrees

Definition: Returns an approximately equivalent angle in degrees from an angle measured in radians.

Syntax:

math.todegrees(radians) β†’ series float

Arguments:

NameTypeDescription

radians

series int/float

Angle in radians.

Returns:

The angle value in degrees.

math.toradians

Definition: Returns an approximately equivalent angle in radians from an angle measured in degrees.

Syntax:

math.toradians(degrees) β†’ series float

Arguments:

NameTypeDescription

degrees

series int/float

Angle in degrees.

Returns:

The angle value in radians.

Last updated