Reference: Maths
Vex reference: maths.
For AI tools: this page as Markdown · the whole language in one file
| Name | What |
|---|---|
max | The largest of the values (empty values are skipped). |
min | The smallest of the values (empty values are skipped). |
abs | x without its sign. |
sqrt | Square root (empty below 0). |
log | Natural logarithm (empty at 0 and below). |
exp | e to the power x. |
round | Nearest whole number. |
floor | Whole number at or below x. |
ceil | Whole number at or above x. |
sign | 1 if x is above 0, -1 below, 0 at 0. |
pow | x to the power p. |
clamp | x kept between lo and hi. |
fallback | x, or y where x is empty. |
empty | True where x has no value (not enough history yet, or a division by zero). |
max
1max(a, b, ...)The largest of the values (empty values are skipped).
Arguments
a: a number per barb: a number per bar
Returns: a number per bar
In Pine Script: math.max(a, b)
Example
1plot(max(close - open, 0))min
1min(a, b, ...)The smallest of the values (empty values are skipped).
Arguments
a: a number per barb: a number per bar
Returns: a number per bar
In Pine Script: math.min(a, b)
Example
1plot(min(open, close))abs
1abs(x)x without its sign.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.abs(x)
Example
1plot(abs(close - open))sqrt
1sqrt(x)Square root (empty below 0).
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.sqrt(x)
Example
1plot(stdev(close, 20) * sqrt(365), "Scaled deviation")log
1log(x)Natural logarithm (empty at 0 and below).
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.log(x)
Example
1plot(log(close))exp
1exp(x)e to the power x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.exp(x)
Example
1plot(exp(roc(close, 1) / 100))round
1round(x)Nearest whole number.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.round(x)
Example
1plot(round(rsi(close, 14)), "RSI, whole")floor
1floor(x)Whole number at or below x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.floor(x)
Example
1plot(floor(close / 100) * 100, "Round hundred below", style = steps)ceil
1ceil(x)Whole number at or above x.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.ceil(x)
Example
1plot(ceil(close / 100) * 100, "Round hundred above", style = steps)sign
1sign(x)1 if x is above 0, -1 below, 0 at 0.
Arguments
x: a number per bar
Returns: a number per bar
In Pine Script: math.sign(x)
Example
1plot(sign(change(close)))pow
1pow(x, p)x to the power p.
Arguments
x: a number per barp: a number per bar
Returns: a number per bar
In Pine Script: math.pow(x, p)
Example
1plot(pow(change(close), 2), "Squared change")clamp
1clamp(x, lo, hi)x kept between lo and hi.
Arguments
x: a number per barlo: a number per barhi: a number per bar
Returns: a number per bar
Example
1plot(clamp(rsi(close, 14), 30, 70), "RSI held to 30-70")fallback
1fallback(x, y)x, or y where x is empty.
Arguments
x: a number per bary: a number per bar
Returns: a number per bar
In Pine Script: nz(x, y)
Example
1plot(fallback(prev(close), close), "Previous close")See also: Empty values, empty
empty
1empty(x)True where x has no value (not enough history yet, or a division by zero).
Arguments
x: a number per bar
Returns: a yes/no per bar
In Pine Script: na(x)
Example
1r = rsi(close, 14)2plot(empty(r) ? 50 : r, "RSI, 50 until ready")See also: Empty values, fallback


