Math
math.abs
math.absDefinition: 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/floatReturns:
The absolute value of `number`.Arguments:
number
simple int/float
The number for which to calculate the absolute value.
math.acos
math.acosDefinition: 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 floatReturns:
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:
angle
simple float
The angle in radians for which to calculate the arccosine.
math.asin
math.asinDefinition: 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 floatReturns:
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:
angle
simple float
The angle in radians for which to calculate the arcsine.
math.atan
math.atanDefinition: 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 floatReturns:
The arc tangent of a value; the returned angle is in the range [-Pi/2, Pi/2].Arguments:
angle
simple float
The angle in radians for which to calculate the arctangent.
math.avg
math.avgDefinition: Calculates the average of all given series (elementwise).
Syntax:
math.avg(number0, number1, ...) → simple float
math.avg(number0, number1, ...) → series floatReturns:
The average value.Arguments:
number0, number1, ...
series float
The series of numbers to calculate the average of. Multiple series can be provided.
math.ceil
math.ceilDefinition: Returns the smallest integer greater than or equal to the argument.
Syntax:
math.ceil(number) → simple int
math.ceil(number) → series intReturns:
The smallest integer greater than or equal to the given number.Arguments:
number
series float
The number to ceil.
math.cos
math.cosDefinition: Returns the trigonometric cosine of an angle.
Syntax:
math.cos(angle) → simple float
math.cos(angle) → series floatReturns:
The trigonometric cosine of an angle.Arguments:
angle
series float
The angle in radians.
math.exp
math.expDefinition: 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 floatReturns:
The value of Euler's number raised to the power of the given number.Arguments:
number
series float
The number for which to calculate the exponent.
math.floor
math.floorDefinition: Returns the largest integer less than or equal to the given number.
Syntax:
math.floor(number) → simple int
math.floor(number) → series intReturns:
The largest integer less than or equal to the given number.Arguments:
number
series int
The number for which to calculate the floor value.
math.log
math.logDefinition: Returns the natural logarithm of any number greater than 0.
Syntax:
math.log(number) → simple float
math.log(number) → series floatReturns:
The natural logarithm of the given number.Arguments:
number
series float
The number for which to calculate the natural logarithm.
math.log10
math.log10Definition: Returns the base 10 logarithm of a number.
Syntax:
math.log10(number) → simple float
math.log10(number) → series floatReturns:
The base 10 logarithm of the given number.Arguments:
number
series float
The number for which to calculate the base 10 logarithm.
math.max
math.maxDefinition: 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/floatReturns:
The greatest of the given values.Arguments:
number0, number1, ...
series int/float
The values to compare and find the greatest among them.
math.min
math.minDefinition: 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/floatReturns:
The smallest of the given values.Arguments:
number0, number1, ...
series int/float
The values to compare and find the smallest among them.
math.pow
math.powDefinition: Mathematical power function.
Syntax:
math.pow(base, exponent) → simple float
math.pow(base, exponent) → series floatReturns:
`base` raised to the power of `exponent`. If `base` is a series, it is calculated elementwise.Arguments:
base
series int/float
Specify the base to use.
exponent
series int/float
Specifies the exponent.
math.random
math.randomDefinition: 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 floatArguments:
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
math.roundDefinition: 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 floatReturns:
The value of `number` rounded to the nearest integer, or according to precision.Arguments:
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
math.signDefinition: 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 floatReturns:
The sign of the argument.Arguments:
number
series int/float
The number for which to determine the sign.
math.sin
math.sinDefinition: The sin function returns the trigonometric sine of an angle.
Syntax:
math.sin(angle) → simple float
math.sin(angle) → series floatReturns:
The trigonometric sine of an angle.Arguments:
angle
series int/float
Angle, in radians.
math.sqrt
math.sqrtDefinition: 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 floatReturns:
The square root of `number`.Arguments:
number
series int/float
The number to calculate the square root of. It must be greater than or equal to 0.
math.sum
math.sumDefinition: The sum function returns the sliding sum of last y values of x.
Syntax:
math.sum(source, length) → series floatArguments:
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
math.tanDefinition: The tan function returns the trigonometric tangent of an angle.
Syntax:
math.tan(angle) → simple float
math.tan(angle) → series floatReturns:
The trigonometric tangent of an angle.Arguments:
angle
series int/float
Angle, in radians.
math.todegrees
math.todegreesDefinition: Returns an approximately equivalent angle in degrees from an angle measured in radians.
Syntax:
math.todegrees(radians) → series floatArguments:
radians
series int/float
Angle in radians.
Returns:
The angle value in degrees.math.toradians
math.toradiansDefinition: Returns an approximately equivalent angle in radians from an angle measured in degrees.
Syntax:
math.toradians(degrees) → series floatArguments:
degrees
series int/float
Angle in degrees.
Returns:
The angle value in radians.Last updated