Functions

Series math

21 names in this group.
Each comes with its signature and an example.

add

a + b per bar

signature
function add(a: Source, b: Source): Series

sub

a − b per bar

signature
function sub(a: Source, b: Source): Series
example
sub(close, open)

mul

a × b per bar

signature
function mul(a: Source, b: Source): Series

div

a ÷ b per bar (÷0 gives NaN)

signature
function div(a: Source, b: Source): Series

abs

Absolute value

signature
function abs(a: Source): Series

max

Larger value per bar

signature
function max(a: Source, b: Source): Series

min

Smaller value per bar

signature
function min(a: Source, b: Source): Series

avg

Average per bar

signature
function avg(...xs: Source[]): Series

gt

a > b

signature
function gt(a: Source, b: Source): Cond
example
gt(close, ta.sma(close, 200))

lt

a < b

signature
function lt(a: Source, b: Source): Cond

gte

a ≥ b

signature
function gte(a: Source, b: Source): Cond

lte

a ≤ b

signature
function lte(a: Source, b: Source): Cond

eq

a = b

signature
function eq(a: Source, b: Source): Cond

and

Both true

signature
function and(a: Bool, b: Bool): Cond

or

Either true

signature
function or(a: Bool, b: Bool): Cond

not

Negation

signature
function not(a: Bool): Cond

prev

The value bars bars ago (default 1)

signature
function prev(src: Source, bars?: number): Series

last

The latest bar’s value

signature
function last(src: Source): number
example
last(close)

nz

NaN replaced by value (default 0)

signature
function nz(src: Source, value?: number): Series

fixnan

NaN replaced by the previous value

signature
function fixnan(src: Source): Series

map

Compute bar by bar, oldest first; outer variables keep state

signature
function map(fn: (i: number) => number | boolean): Series
example
map(i => (high[i] - low[i]) / close[i] * 100)

npm · GitHub