Usage

All math functions are accessed through the math namespace and use keyword arguments:

Basic Math Function Usage

Mathematical Constants

math.E

2.718

Euler's number, the base of natural logarithms

math.PI

3.142

The ratio of a circle's circumference to its diameter

math.SQRT2

1.414

The square root of 2

math.SQRT1_2

0.707

The square root of 1/2

math.LN2

0.693

The natural logarithm of 2

math.LN10

2.303

The natural logarithm of 10

math.LOG2E

1.443

The base-2 logarithm of E

math.LOG10E

0.434

The base-10 logarithm of E

Available Functions

math.abs()

Basic

Returns the absolute value of a number

Usage: math.abs(value)

math.ceil()

Rounding

Returns the smallest integer greater than or equal to the given number

Usage: math.ceil(value)

math.floor()

Rounding

Returns the largest integer less than or equal to the given number

Usage: math.floor(value)

math.round()

Rounding

Returns the value rounded to the nearest integer

Usage: math.round(value)

math.trunc()

Rounding

Returns the integer part of a number by removing fractional digits

Usage: math.trunc(value)

math.sign()

Basic

Returns the sign of a number: 1, -1, or 0

Usage: math.sign(value)

math.max()

Comparison

Returns the largest of the given numbers

Usage: math.max(a, b, ...)

math.min()

Comparison

Returns the smallest of the given numbers

Usage: math.min(a, b, ...)

math.random()

Basic

Returns a random number between 0 and 1

Usage: math.random()

math.sin()

Trigonometric

Returns the sine of a number (in radians)

Usage: math.sin(value)

math.cos()

Trigonometric

Returns the cosine of a number (in radians)

Usage: math.cos(value)

math.tan()

Trigonometric

Returns the tangent of a number (in radians)

Usage: math.tan(value)

math.asin()

Trigonometric

Returns the arcsine of a number, in radians

Usage: math.asin(value)

math.acos()

Trigonometric

Returns the arccosine of a number, in radians

Usage: math.acos(value)

math.atan()

Trigonometric

Returns the arctangent of a number, in radians

Usage: math.atan(value)

math.atan2()

Trigonometric

Returns the arctangent of y/x, in radians

Usage: math.atan2(y, x)

math.sinh()

Hyperbolic

Returns the hyperbolic sine of a number

Usage: math.sinh(value)

math.cosh()

Hyperbolic

Returns the hyperbolic cosine of a number

Usage: math.cosh(value)

math.tanh()

Hyperbolic

Returns the hyperbolic tangent of a number

Usage: math.tanh(value)

math.asinh()

Hyperbolic

Returns the inverse hyperbolic sine of a number

Usage: math.asinh(value)

math.acosh()

Hyperbolic

Returns the inverse hyperbolic cosine of a number

Usage: math.acosh(value)

math.atanh()

Hyperbolic

Returns the inverse hyperbolic tangent of a number

Usage: math.atanh(value)

math.exp()

Exponential

Returns e raised to the power of the given number

Usage: math.exp(value)

math.expm1()

Exponential

Returns e^x - 1

Usage: math.expm1(value)

math.log()

Logarithmic

Returns the natural logarithm of a number

Usage: math.log(value)

math.log1p()

Logarithmic

Returns the natural logarithm of 1 + x

Usage: math.log1p(value)

math.log2()

Logarithmic

Returns the base-2 logarithm of a number

Usage: math.log2(value)

math.log10()

Logarithmic

Returns the base-10 logarithm of a number

Usage: math.log10(value)

math.pow()

Exponential

Returns base raised to the power of exponent

Usage: math.pow(base, exponent)

math.sqrt()

Root

Returns the square root of a number

Usage: math.sqrt(value)

math.cbrt()

Root

Returns the cube root of a number

Usage: math.cbrt(value)

math.hypot()

Root

Returns the square root of the sum of squares of arguments

Usage: math.hypot(a, b, ...)
📖
Introduction
Overview of kScript language
🔍
Overview
Complete technical documentation
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
📚
Type System
Understanding kScript data types
General FAQ
Frequently asked questions about kScript
Best Practices
Guidelines for writing efficient kScript code
⚠️
Limitations
Known constraints and workarounds
🆕
Updates
v1 vs v2 differences and improvements
🔧
Core Concepts
Variables, data types & data sources
⚙️
Execution Model
Per-bar execution lifecycle and phases
🏷️
Keyword Arguments
Named parameters for clear function calls
🔗
Field Accessors
Dot notation for timeseries field access
🛠️
User-Defined Functions
Create custom reusable functions
🔗
Script Definition
Defining inputs and metadata
TimeSeries Management
Working with time-aligned data
🎯
Utility Functions
Helper functions and calculations
📈
Moving Averages
SMA, EMA and trend-following indicators
📊
Oscillators
RSI, Stochastic and momentum indicators
📈
Trend Indicators
Trend direction and strength analysis
📉
Volume Indicators
Volume-based analysis tools
📦
Orderbook Functions
Market depth analysis tools
🎨
Plotting & Visualization
Chart rendering and styling
🌈
Color Functions
Color manipulation and styling
📊
Data Subscriptions
Subscribe to OHLCV, trades, and orderbook data
🔄
Loops
For loops and while loops for iteration
🧮
Math Functions
Mathematical functions and constants
🏠
Go Home
Return to main landing page