Skip to main content
Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: math · Entries: 107

math (library)

Definition Twenty-three arithmetic and trigonometric functions, and four constants: math.pi, math.e, math.phi and math.rphi. math.log is the natural logarithm (base e); math.log10 is the base-10 logarithm. Example

math.abs (function, overload 1)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns const int Example

math.abs (function, overload 2)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns input int Example

math.abs (function, overload 3)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns simple int Example

math.abs (function, overload 4)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns series int Example

math.abs (function, overload 5)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns const float Example

math.abs (function, overload 6)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns input float Example

math.abs (function, overload 7)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns simple float Example

math.abs (function, overload 8)

Definition The absolute value of number: its magnitude, with the sign removed. Syntax
Parameters Returns series float Example

math.acos (function, overload 1)

Definition The arccosine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns const float Example

math.acos (function, overload 2)

Definition The arccosine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns input float Example

math.acos (function, overload 3)

Definition The arccosine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns simple float Example

math.acos (function, overload 4)

Definition The arccosine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns series float Example

math.asin (function, overload 1)

Definition The arcsine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns const float Example

math.asin (function, overload 2)

Definition The arcsine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns input float Example

math.asin (function, overload 3)

Definition The arcsine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns simple float Example

math.asin (function, overload 4)

Definition The arcsine of angle, in radians. It is defined for a value from -1 to 1. Syntax
Parameters Returns series float Example

math.atan (function, overload 1)

Definition The arctangent of angle, in radians. It is defined for every number. Syntax
Parameters Returns const float Example

math.atan (function, overload 2)

Definition The arctangent of angle, in radians. It is defined for every number. Syntax
Parameters Returns input float Example

math.atan (function, overload 3)

Definition The arctangent of angle, in radians. It is defined for every number. Syntax
Parameters Returns simple float Example

math.atan (function, overload 4)

Definition The arctangent of angle, in radians. It is defined for every number. Syntax
Parameters Returns series float Example

math.avg (function, overload 1)

Definition The arithmetic mean of the numbers you pass: their sum divided by how many there are. It averages the arguments in the one call. It does not average a value across bars, and it takes no length argument. Syntax
Parameters Returns const float Example

math.avg (function, overload 2)

Definition The arithmetic mean of the numbers you pass: their sum divided by how many there are. It averages the arguments in the one call. It does not average a value across bars, and it takes no length argument. Syntax
Parameters Returns input float Example

math.avg (function, overload 3)

Definition The arithmetic mean of the numbers you pass: their sum divided by how many there are. It averages the arguments in the one call. It does not average a value across bars, and it takes no length argument. Syntax
Parameters Returns simple float Example

math.avg (function, overload 4)

Definition The arithmetic mean of the numbers you pass: their sum divided by how many there are. It averages the arguments in the one call. It does not average a value across bars, and it takes no length argument. Syntax
Parameters Returns series float Example

math.ceil (function, overload 1)

Definition The smallest whole number that is not less than number. The result is an int, not a float. Syntax
Parameters Returns const int Example

math.ceil (function, overload 2)

Definition The smallest whole number that is not less than number. The result is an int, not a float. Syntax
Parameters Returns input int Example

math.ceil (function, overload 3)

Definition The smallest whole number that is not less than number. The result is an int, not a float. Syntax
Parameters Returns simple int Example

math.ceil (function, overload 4)

Definition The smallest whole number that is not less than number. The result is an int, not a float. Syntax
Parameters Returns series int Example

math.cos (function, overload 1)

Definition The cosine of angle, where the angle is in radians. Syntax
Parameters Returns const float Example

math.cos (function, overload 2)

Definition The cosine of angle, where the angle is in radians. Syntax
Parameters Returns input float Example

math.cos (function, overload 3)

Definition The cosine of angle, where the angle is in radians. Syntax
Parameters Returns simple float Example

math.cos (function, overload 4)

Definition The cosine of angle, where the angle is in radians. Syntax
Parameters Returns series float Example

math.exp (function, overload 1)

Definition Euler’s number raised to the power of number. It is the inverse of math.log. Syntax
Parameters Returns const float Example

math.exp (function, overload 2)

Definition Euler’s number raised to the power of number. It is the inverse of math.log. Syntax
Parameters Returns input float Example

math.exp (function, overload 3)

Definition Euler’s number raised to the power of number. It is the inverse of math.log. Syntax
Parameters Returns simple float Example

math.exp (function, overload 4)

Definition Euler’s number raised to the power of number. It is the inverse of math.log. Syntax
Parameters Returns series float Example

math.floor (function, overload 1)

Definition The largest whole number that is not greater than number. The result is an int, not a float. Syntax
Parameters Returns const int Example

math.floor (function, overload 2)

Definition The largest whole number that is not greater than number. The result is an int, not a float. Syntax
Parameters Returns input int Example

math.floor (function, overload 3)

Definition The largest whole number that is not greater than number. The result is an int, not a float. Syntax
Parameters Returns simple int Example

math.floor (function, overload 4)

Definition The largest whole number that is not greater than number. The result is an int, not a float. Syntax
Parameters Returns series int Example

math.log (function, overload 1)

Definition The natural logarithm of number: its logarithm to base e. It is defined for a number greater than zero. For base 10, use math.log10. Syntax
Parameters Returns const float Notes
  • The compiler also accepts math.log10. math.log2 is rejected.
Example

math.log (function, overload 2)

Definition The natural logarithm of number: its logarithm to base e. It is defined for a number greater than zero. For base 10, use math.log10. Syntax
Parameters Returns input float Notes
  • The compiler also accepts math.log10. math.log2 is rejected.
Example

math.log (function, overload 3)

Definition The natural logarithm of number: its logarithm to base e. It is defined for a number greater than zero. For base 10, use math.log10. Syntax
Parameters Returns simple float Notes
  • The compiler also accepts math.log10. math.log2 is rejected.
Example

math.log (function, overload 4)

Definition The natural logarithm of number: its logarithm to base e. It is defined for a number greater than zero. For base 10, use math.log10. Syntax
Parameters Returns series float Notes
  • The compiler also accepts math.log10. math.log2 is rejected.
Example

math.log10 (function, overload 1)

Definition The base-10 logarithm of number. It is defined for a number greater than zero; otherwise the result is na. Syntax
Parameters Returns const float Example

math.log10 (function, overload 2)

Definition The base-10 logarithm of number. It is defined for a number greater than zero; otherwise the result is na. Syntax
Parameters Returns input float Example

math.log10 (function, overload 3)

Definition The base-10 logarithm of number. It is defined for a number greater than zero; otherwise the result is na. Syntax
Parameters Returns simple float Example

math.log10 (function, overload 4)

Definition The base-10 logarithm of number. It is defined for a number greater than zero; otherwise the result is na. Syntax
Parameters Returns series float Example

math.max (function, overload 1)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns const int The greatest of the given numbers. Example

math.max (function, overload 2)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns input int The greatest of the given numbers. Example

math.max (function, overload 3)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns simple int The greatest of the given numbers. Example

math.max (function, overload 4)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns series int The greatest of the given numbers. Example

math.max (function, overload 5)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns const float The greatest of the given numbers. Example

math.max (function, overload 6)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns input float The greatest of the given numbers. Example

math.max (function, overload 7)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns simple float The greatest of the given numbers. Example

math.max (function, overload 8)

Definition The largest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns series float The greatest of the given numbers. Example

math.min (function, overload 1)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns const int The smallest of the given numbers. Example

math.min (function, overload 2)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns input int The smallest of the given numbers. Example

math.min (function, overload 3)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns simple int The smallest of the given numbers. Example

math.min (function, overload 4)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns series int The smallest of the given numbers. Example

math.min (function, overload 5)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns const float The smallest of the given numbers. Example

math.min (function, overload 6)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns input float The smallest of the given numbers. Example

math.min (function, overload 7)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns simple float The smallest of the given numbers. Example

math.min (function, overload 8)

Definition The smallest of the numbers you pass. It compares the arguments in the one call. It does not look back over bars, and it takes no length argument. Syntax
Parameters Returns series float The smallest of the given numbers. Example

math.pow (function, overload 1)

Definition base raised to the power of exponent. The language has no exponentiation operator: a token for one exists in the lexer but no rule reaches it, so source containing ^ does not parse. This function is how you raise a number to a power. Syntax
Parameters Returns const float Example

math.pow (function, overload 2)

Definition base raised to the power of exponent. The language has no exponentiation operator: a token for one exists in the lexer but no rule reaches it, so source containing ^ does not parse. This function is how you raise a number to a power. Syntax
Parameters Returns input float Example

math.pow (function, overload 3)

Definition base raised to the power of exponent. The language has no exponentiation operator: a token for one exists in the lexer but no rule reaches it, so source containing ^ does not parse. This function is how you raise a number to a power. Syntax
Parameters Returns simple float Example

math.pow (function, overload 4)

Definition base raised to the power of exponent. The language has no exponentiation operator: a token for one exists in the lexer but no rule reaches it, so source containing ^ does not parse. This function is how you raise a number to a power. Syntax
Parameters Returns series float Example

math.random (function)

Definition Gives your script a random float, bounded below by min and above by max. Both bounds are optional. There is no seed argument, so a result cannot be reproduced. Keep the value out of anything a reader is meant to compare between runs. It has a single form, series. A series value is refused wherever a narrower form is required, so this result cannot fill a const, input or simple argument - a script’s title, for instance. Syntax
Parameters Returns series float Example

math.round (function, overload 1)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns const int Example

math.round (function, overload 2)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns input int Example

math.round (function, overload 3)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns simple int Example

math.round (function, overload 4)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns series int Example

math.round (function, overload 5)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns const float Example

math.round (function, overload 6)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns input float Example

math.round (function, overload 7)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns simple float Example

math.round (function, overload 8)

Definition Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar. Syntax
Parameters Returns series float Example

math.round_to_mintick (function, overload 1)

Definition Rounds number to the nearest multiple of syminfo.mintick for the chart symbol. Uses floor(number / mintick + 0.5) * mintick. Returns na when the input is na or when syminfo.mintick is not available. Syntax
Parameters Returns const float Rounded float on the symbol’s tick grid. Example

math.round_to_mintick (function, overload 2)

Definition Rounds number to the nearest multiple of syminfo.mintick for the chart symbol. Uses floor(number / mintick + 0.5) * mintick. Returns na when the input is na or when syminfo.mintick is not available. Syntax
Parameters Returns input float Rounded float on the symbol’s tick grid. Example

math.round_to_mintick (function, overload 3)

Definition Rounds number to the nearest multiple of syminfo.mintick for the chart symbol. Uses floor(number / mintick + 0.5) * mintick. Returns na when the input is na or when syminfo.mintick is not available. Syntax
Parameters Returns simple float Rounded float on the symbol’s tick grid. Example

math.round_to_mintick (function, overload 4)

Definition Rounds number to the nearest multiple of syminfo.mintick for the chart symbol. Uses floor(number / mintick + 0.5) * mintick. Returns na when the input is na or when syminfo.mintick is not available. Syntax
Parameters Returns series float Rounded float on the symbol’s tick grid. Example

math.sign (function, overload 1)

Definition The sign of number: -1 for a negative number and 1 for a positive one. The result is a float, not an int. Every other member that reduces a number to a whole value - math.ceil, math.floor, the one-argument math.round - returns an int, so this one is worth reading twice. Syntax
Parameters Returns const float Example

math.sign (function, overload 2)

Definition The sign of number: -1 for a negative number and 1 for a positive one. The result is a float, not an int. Every other member that reduces a number to a whole value - math.ceil, math.floor, the one-argument math.round - returns an int, so this one is worth reading twice. Syntax
Parameters Returns input float Example

math.sign (function, overload 3)

Definition The sign of number: -1 for a negative number and 1 for a positive one. The result is a float, not an int. Every other member that reduces a number to a whole value - math.ceil, math.floor, the one-argument math.round - returns an int, so this one is worth reading twice. Syntax
Parameters Returns simple float Example

math.sign (function, overload 4)

Definition The sign of number: -1 for a negative number and 1 for a positive one. The result is a float, not an int. Every other member that reduces a number to a whole value - math.ceil, math.floor, the one-argument math.round - returns an int, so this one is worth reading twice. Syntax
Parameters Returns series float Example

math.sin (function, overload 1)

Definition The sine of angle, where the angle is in radians. Syntax
Parameters Returns const float Example

math.sin (function, overload 2)

Definition The sine of angle, where the angle is in radians. Syntax
Parameters Returns input float Example

math.sin (function, overload 3)

Definition The sine of angle, where the angle is in radians. Syntax
Parameters Returns simple float Example

math.sin (function, overload 4)

Definition The sine of angle, where the angle is in radians. Syntax
Parameters Returns series float Example

math.sqrt (function, overload 1)

Definition The square root of number. It is defined for a number that is not negative. Syntax
Parameters Returns const float Example

math.sqrt (function, overload 2)

Definition The square root of number. It is defined for a number that is not negative. Syntax
Parameters Returns input float Example

math.sqrt (function, overload 3)

Definition The square root of number. It is defined for a number that is not negative. Syntax
Parameters Returns simple float Example

math.sqrt (function, overload 4)

Definition The square root of number. It is defined for a number that is not negative. Syntax
Parameters Returns series float Example

math.sum (function)

Definition Adds up the last length values of source. Same behavior as talib.sum — a moving window, not a running total (talib.cum). Syntax
Parameters Returns series float A series float total. Example

math.tan (function, overload 1)

Definition The tangent of angle, where the angle is in radians. Syntax
Parameters Returns const float Notes
  • In this build math.tan returns na when angle is exactly 90 (radians); every other value gives the tangent. As the default of input.float, math.tan(90) is refused when the script is added to the chart (“Argument defval of input.float() cannot be na.”), while math.tan(89) is accepted.
Example

math.tan (function, overload 2)

Definition The tangent of angle, where the angle is in radians. Syntax
Parameters Returns input float Notes
  • In this build math.tan returns na when angle is exactly 90 (radians); every other value gives the tangent. As the default of input.float, math.tan(90) is refused when the script is added to the chart (“Argument defval of input.float() cannot be na.”), while math.tan(89) is accepted.
Example

math.tan (function, overload 3)

Definition The tangent of angle, where the angle is in radians. Syntax
Parameters Returns simple float Notes
  • In this build math.tan returns na when angle is exactly 90 (radians); every other value gives the tangent. As the default of input.float, math.tan(90) is refused when the script is added to the chart (“Argument defval of input.float() cannot be na.”), while math.tan(89) is accepted.
Example

math.tan (function, overload 4)

Definition The tangent of angle, where the angle is in radians. Syntax
Parameters Returns series float Notes
  • In this build math.tan returns na when angle is exactly 90 (radians); every other value gives the tangent. As the default of input.float, math.tan(90) is refused when the script is added to the chart (“Argument defval of input.float() cannot be na.”), while math.tan(89) is accepted.
Example

math.todegrees (function, overload 1)

Definition Converts an angle in radians to the same angle in degrees. Syntax
Parameters Returns const float Example

math.todegrees (function, overload 2)

Definition Converts an angle in radians to the same angle in degrees. Syntax
Parameters Returns input float Example

math.todegrees (function, overload 3)

Definition Converts an angle in radians to the same angle in degrees. Syntax
Parameters Returns simple float Example

math.todegrees (function, overload 4)

Definition Converts an angle in radians to the same angle in degrees. Syntax
Parameters Returns series float Example

math.toradians (function, overload 1)

Definition Converts an angle in degrees to the same angle in radians. The trigonometric functions take radians, so this is the conversion to reach for before calling them. Syntax
Parameters Returns const float Example

math.toradians (function, overload 2)

Definition Converts an angle in degrees to the same angle in radians. The trigonometric functions take radians, so this is the conversion to reach for before calling them. Syntax
Parameters Returns input float Example

math.toradians (function, overload 3)

Definition Converts an angle in degrees to the same angle in radians. The trigonometric functions take radians, so this is the conversion to reach for before calling them. Syntax
Parameters Returns simple float Example

math.toradians (function, overload 4)

Definition Converts an angle in degrees to the same angle in radians. The trigonometric functions take radians, so this is the conversion to reach for before calling them. Syntax
Parameters Returns series float Example