Skip to content

Script Engine Std Library

Collection of standard TA (technical analysis) functions.

Functions

prop(name, descr)

Declare new script property

autoPrec()number

Get precision of ohlc dataset

ts(x)TS

Creates a new time-series & records each x. Returns an array. Id is auto-genrated

tstf(x, tf)TS

Creates a new time-series & records each x. Uses Sampler to aggregate the values Return the an array. Id is auto-genrated

sample(x, type, tf)TS

Creates a new custom sampler. Return the an array. Id is auto-genrated

nz(x, [v])*

Replaces the variable if it's NaN

na(x)boolean

Is the variable NaN ?

nf(x, [v])*

Replaces the var with NaN if Infinite

add(x, y)TS

Adds values / time-series

sub(x, y)TS

Subtracts values / time-series

mult(x, y)TS

Multiplies values / time-series

div(x, y)TS

Divides values / time-series

neg(x)TS

Returns a negative value / time-series

abs(x)number

Absolute value

acos(x)number

Arccosine function

signal(type, data)

Emits an event to DataCube

signalif(cond, type, data)

Emits an event if cond === true

alma(src, len, offset, sigma)TS

Arnaud Legoux Moving Average

asin(x)number

Arcsine function

atan(x)number

Arctangent function

atr(len)TS

Average True Range

avg(...args)number

Average of arguments

since(cond)

Candles since the event occured (cond === true)

bb(src, len, mult)Array.<TS>

Bollinger Bands

bbw(src, len, mult)TS

Bollinger Bands Width

bool(x)number

Converts the variable to Boolean

cci(src, len)TS

Commodity Channel Index

ceil(x)number

Shortcut for Math.ceil()

change(src, [len])TS

Change: x[0] - x[len]

cmo(src, len)TS

Chande Momentum Oscillator

cog(src, len)TS

Center of Gravity

cos(x)number

Cosine function

cross(src1, src2)TS

When one time-series crosses another

crossover(src1, src2)TS

When one time-series goes over another one

crossunder(src1, src2)TS

When one time-series goes under another one

cum(src1)TS

Sum of all elements of src

dayofmonth([time])number

Day of month, literally

dayofweek([time])number

Day of week, literally

dev(src, len)TS

Deviation from SMA

dmi(len, smooth)TS

Directional Movement Index ADX, +DI, -DI

ema(src, len)TS

Exponential Moving Average with alpha = 2 / (y + 1)

exp(x)number

Shortcut for Math.exp()

falling(src, len)TS

Test if "src" TS is falling for "len" candles

fixnan(src)TS

For a given series replaces NaN values with previous nearest non-NaN value

floor(x)number

Shortcut for Math.floor()

highest(src, len)TS

Highest value for a given number of candles back

highestbars(src, len)

Highest value offset for a given number of bars back

hma(src, len)TS

Hull Moving Average

hour([time])number

Returns hours of a given timestamp

iff(cond, x, y)*

Returns x or y depending on the condition

kc(src, len, mult, [use_tr])Array.<TS>

Keltner Channels

kcw(src, len, mult, [use_tr])TS

Keltner Channels Width

linreg(src, len, offset)TS

Linear Regression

log(x)number

Shortcut for Math.log()

log10(x)number

Shortcut for Math.log10()

lowest(src, len)TS

Lowest value for a given number of candles back

lowestbars(src, len)

Lowest value offset for a given number of bars back

macd(src, fast, slow, sig)Array.<TS>

Moving Average Convergence/Divergence

max(...args)number

Max of arguments

modify(id, fields)

Sends update to some overlay / main chart

buffsize(src, len)

Sets the reverse buffer size for a given time-series (default = 5, grows on demand)

mfi(src, len)TS

Money Flow Index

min(...args)number

Min of arguments

minute([time])number

Returns minutes of a given timestamp

mom(src, len)TS

Momentum

month([time])number

Month

chart(x, [sett])

Display data point as the main chart

onclose(tf)boolean

Returns true when the candle(tf) is being closed (create a new overlay in DataCube)

settings(upd)

Sends settings update (can be called from init(), update() or post())

offset(num)TS

Shifts TS left or right by "num" candles

now()number

The current time

pivothigh(src, left, right)TS

Returns price of the pivot high point Tip: works best with offset function

pivotlow(src, left, right)TS

Returns price of the pivot low point Tip: works best with offset function

pow(x)number

Shortcut for Math.pow()

rising(src, len)TS

Test if "src" TS is rising for "len" candles

rma(src, len)TS

Exponentially MA with alpha = 1 / length Used in RSI

roc(src, len)TS

Rate of Change

round(x)number

Shortcut for Math.round()

rsi(x, y)TS

Relative Strength Index

sar(start, inc, max)TS

Parabolic SAR

second([time])number

Returns seconds of a given timestamp

sign(x)number

Shortcut for Math.sing()

sin(x)number

Sine function

sma(src, len)TS

Simple Moving Average

sqrt(x)number

Shortcut for Math.sqrt()

stdev(src, len)TS

Standard deviation

stoch(src, high, low, len)TS

Stochastic

sum(src, len)TS

Returns the sliding sum of last "len" values of the source

supertrend(factor, atrlen)Array.<TS>

Supertrend Indicator

swma(src)TS

Symmetrically Weighted Moving Average

sym(x, y)Sym

Creates a new Symbol.

tan(x)number

Tangent function

tr(fixnan)TS

True Range

tsi(src, short, long)TS

True strength index

view(name, props)

Create a new View

vwma(src, len)TS

Volume Weighted Moving Average

weekofyear([time])number

Week of year, literally

wma(src, len)TS

Weighted moving average

wpr(len)TS

Williams %R

year([time])number

Year

prop

prop(name, descr)

Declare new script property

Kind: global function

ParamTypeDescription
namestringPropery name
descrstringPropery descriptor

autoPrec

autoPrec() ⇒ number

Get precision of ohlc dataset

Kind: global function
Returns: number - - Ohlc preciosion

ts

ts(x) ⇒ TS

Creates a new time-series & records each x. Returns an array. Id is auto-genrated

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
x*A variable to sample from

tstf

tstf(x, tf) ⇒ TS

Creates a new time-series & records each x. Uses Sampler to aggregate the values Return the an array. Id is auto-genrated

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
x*A variable to sample from
tfnumber | stringTimeframe in ms or as a string

sample

sample(x, type, tf) ⇒ TS

Creates a new custom sampler. Return the an array. Id is auto-genrated

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
x*A variable to sample from
typestringSampler type
tfnumber | stringTimeframe in ms or as a string

nz

nz(x, [v]) ⇒ *

Replaces the variable if it's NaN

Kind: global function
Returns: * - - New value

ParamTypeDescription
x*The variable
[v]*A value to replace with

na

na(x) ⇒ boolean

Is the variable NaN ?

Kind: global function
Returns: boolean - - New value

ParamTypeDescription
x*The variable

nf

nf(x, [v]) ⇒ *

Replaces the var with NaN if Infinite

Kind: global function
Returns: * - - New value

ParamTypeDescription
x*The variable
[v]*A value to replace with

add

add(x, y) ⇒ TS

Adds values / time-series

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTS | *First input
yTS | *Second input

sub

sub(x, y) ⇒ TS

Subtracts values / time-series

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTS | *First input
yTS | *Second input

mult

mult(x, y) ⇒ TS

Multiplies values / time-series

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTS | *First input
yTS | *Second input

div

div(x, y) ⇒ TS

Divides values / time-series

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTS | *First input
yTS | *Second input

neg

neg(x) ⇒ TS

Returns a negative value / time-series

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTS | *Input

abs

abs(x) ⇒ number

Absolute value

Kind: global function
Returns: number - - Absolute value

ParamTypeDescription
xnumberInput

acos

acos(x) ⇒ number

Arccosine function

Kind: global function
Returns: number - - Arccosine of x

ParamTypeDescription
xnumberInput

signal

signal(type, data)

Emits an event to DataCube

Kind: global function

ParamTypeDescription
typestringSignal type
data*Signal data

signalif

signalif(cond, type, data)

Emits an event if cond === true

Kind: global function

ParamTypeDescription
condboolean | TSThe condition
typestringSignal type
data*Signal data

alma

alma(src, len, offset, sigma) ⇒ TS

Arnaud Legoux Moving Average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength
offsetnumberOffset
sigmanumberSigma

asin

asin(x) ⇒ number

Arcsine function

Kind: global function
Returns: number - - Arcsine of x

ParamTypeDescription
xnumberInput

atan

atan(x) ⇒ number

Arctangent function

Kind: global function
Returns: number - - Arctangent of x

ParamTypeDescription
xnumberInput

atr

atr(len) ⇒ TS

Average True Range

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
lennumberLength

avg

avg(...args) ⇒ number

Average of arguments

Kind: global function

ParamTypeDescription
...argsnumberNumeric values

since

since(cond)

Candles since the event occured (cond === true)

Kind: global function

ParamTypeDescription
condboolean | TSthe condition

bb

bb(src, len, mult) ⇒ Array.<TS>

Bollinger Bands

Kind: global function
Returns: Array.<TS> - - Array of new time-series (3 bands)

ParamTypeDescription
srcTSInput
lennumberLength
multnumberMultiplier

bbw

bbw(src, len, mult) ⇒ TS

Bollinger Bands Width

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength
multnumberMultiplier

bool

bool(x) ⇒ number

Converts the variable to Boolean

Kind: global function

ParamTypeDescription
xnumberThe variable

cci

cci(src, len) ⇒ TS

Commodity Channel Index

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

ceil

ceil(x) ⇒ number

Shortcut for Math.ceil()

Kind: global function

ParamTypeDescription
xnumberThe variable

change

change(src, [len]) ⇒ TS

Change: x[0] - x[len]

Kind: global function
Returns: TS - - New time-series

ParamTypeDefaultDescription
srcTSInput
[len]number1Length

cmo

cmo(src, len) ⇒ TS

Chande Momentum Oscillator

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

cog

cog(src, len) ⇒ TS

Center of Gravity

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

cos

cos(x) ⇒ number

Cosine function

Kind: global function
Returns: number - - Cosine of x

ParamTypeDescription
xnumberInput

cross

cross(src1, src2) ⇒ TS

When one time-series crosses another

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
src1TSTS1
src2TSTS2

crossover

crossover(src1, src2) ⇒ TS

When one time-series goes over another one

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
src1TSTS1
src2TSTS2

crossunder

crossunder(src1, src2) ⇒ TS

When one time-series goes under another one

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
src1TSTS1
src2TSTS2

cum

cum(src1) ⇒ TS

Sum of all elements of src

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
src1TSInput

dayofmonth

dayofmonth([time]) ⇒ number

Day of month, literally

Kind: global function
Returns: number - - Day

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

dayofweek

dayofweek([time]) ⇒ number

Day of week, literally

Kind: global function
Returns: number - - Day

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

dev

dev(src, len) ⇒ TS

Deviation from SMA

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

dmi

dmi(len, smooth) ⇒ TS

Directional Movement Index ADX, +DI, -DI

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
lennumberLength
smoothnumberSmoothness

ema

ema(src, len) ⇒ TS

Exponential Moving Average with alpha = 2 / (y + 1)

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

exp

exp(x) ⇒ number

Shortcut for Math.exp()

Kind: global function

ParamTypeDescription
xnumberThe variable

falling

falling(src, len) ⇒ TS

Test if "src" TS is falling for "len" candles

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

fixnan

fixnan(src) ⇒ TS

For a given series replaces NaN values with previous nearest non-NaN value

Kind: global function

ParamTypeDescription
srcTSInput time-series

floor

floor(x) ⇒ number

Shortcut for Math.floor()

Kind: global function

ParamTypeDescription
xnumberThe variable

highest

highest(src, len) ⇒ TS

Highest value for a given number of candles back

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

highestbars

highestbars(src, len)

Highest value offset for a given number of bars back

Kind: global function

ParamTypeDescription
srcTSInput
lennumberLength

hma

hma(src, len) ⇒ TS

Hull Moving Average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

hour

hour([time]) ⇒ number

Returns hours of a given timestamp

Kind: global function
Returns: number - - Hour

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

iff

iff(cond, x, y) ⇒ *

Returns x or y depending on the condition

Kind: global function

ParamTypeDescription
condboolean | TSCondition
x*Frist value
y*Second value

kc

kc(src, len, mult, [use_tr]) ⇒ Array.<TS>

Keltner Channels

Kind: global function
Returns: Array.<TS> - - Array of new time-series (3 bands)

ParamTypeDefaultDescription
srcTSInput
lennumberLength
multnumberMultiplier
[use_tr]booleantrueUse true range

kcw

kcw(src, len, mult, [use_tr]) ⇒ TS

Keltner Channels Width

Kind: global function
Returns: TS - - New time-series

ParamTypeDefaultDescription
srcTSInput
lennumberLength
multnumberMultiplier
[use_tr]booleantrueUse true range

linreg

linreg(src, len, offset) ⇒ TS

Linear Regression

Kind: global function
Returns: TS - - New time-series

ParamTypeDefaultDescription
srcTSInput
lennumberLength
offsetnumber0Offset

log

log(x) ⇒ number

Shortcut for Math.log()

Kind: global function

ParamTypeDescription
xnumberThe variable

log10

log10(x) ⇒ number

Shortcut for Math.log10()

Kind: global function

ParamTypeDescription
xnumberThe variable

lowest

lowest(src, len) ⇒ TS

Lowest value for a given number of candles back

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

lowestbars

lowestbars(src, len)

Lowest value offset for a given number of bars back

Kind: global function

ParamTypeDescription
srcTSInput
lennumberLength

macd

macd(src, fast, slow, sig) ⇒ Array.<TS>

Moving Average Convergence/Divergence

Kind: global function
Returns: Array.<TS> - - [macd, signal, hist]

ParamTypeDescription
srcTSInput
fastnumberFast EMA
slownumberSlow EMA
signumberSignal

max

max(...args) ⇒ number

Max of arguments

Kind: global function

ParamTypeDescription
...argsnumberNumeric values

modify

modify(id, fields)

Sends update to some overlay / main chart

Kind: global function

ParamTypeDescription
idstringOverlay id
fieldsObjectFields to be overwritten

buffsize

buffsize(src, len)

Sets the reverse buffer size for a given time-series (default = 5, grows on demand)

Kind: global function

ParamTypeDescription
srcTSInput
lennumberNew length

mfi

mfi(src, len) ⇒ TS

Money Flow Index

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

min

min(...args) ⇒ number

Min of arguments

Kind: global function

ParamTypeDescription
...argsnumberNumeric values

minute

minute([time]) ⇒ number

Returns minutes of a given timestamp

Kind: global function
Returns: number - - Hour

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

mom

mom(src, len) ⇒ TS

Momentum

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

month

month([time]) ⇒ number

Month

Kind: global function
Returns: number - - Day

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

chart

chart(x, [sett])

Display data point as the main chart

Kind: global function

ParamTypeDescription
xTS | Array.<TS> | *Data point / TS / array of TS
[sett]ObjectObject with settings & OV type

onclose

onclose(tf) ⇒ boolean

Returns true when the candle(tf) is being closed (create a new overlay in DataCube)

Kind: global function

ParamTypeDescription
tfnumber | stringTimeframe in ms or as a string

settings

settings(upd)

Sends settings update (can be called from init(), update() or post())

Kind: global function

ParamTypeDescription
updObjectSettings update (object to merge)

offset

offset(num) ⇒ TS

Shifts TS left or right by "num" candles

Kind: global function
Returns: TS - - New / existing time-series

ParamTypeDescription
numnumberOffset measured in candles

now

now() ⇒ number

The current time

Kind: global function
Returns: number - - timestamp

pivothigh

pivothigh(src, left, right) ⇒ TS

Returns price of the pivot high point Tip: works best with offset function

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
leftnumberleft threshold, candles
rightnumberright threshold, candles

pivotlow

pivotlow(src, left, right) ⇒ TS

Returns price of the pivot low point Tip: works best with offset function

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
leftnumberleft threshold, candles
rightnumberright threshold, candles

pow

pow(x) ⇒ number

Shortcut for Math.pow()

Kind: global function

ParamTypeDescription
xnumberThe variable

rising

rising(src, len) ⇒ TS

Test if "src" TS is rising for "len" candles

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

rma

rma(src, len) ⇒ TS

Exponentially MA with alpha = 1 / length Used in RSI

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

roc

roc(src, len) ⇒ TS

Rate of Change

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

round

round(x) ⇒ number

Shortcut for Math.round()

Kind: global function

ParamTypeDescription
xnumberThe variable

rsi

rsi(x, y) ⇒ TS

Relative Strength Index

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
xTSFirst Input
ynumber | TSSecond Input

sar

sar(start, inc, max) ⇒ TS

Parabolic SAR

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
startnumberStart
incnumberIncrement
maxnumberMaximum

second

second([time]) ⇒ number

Returns seconds of a given timestamp

Kind: global function
Returns: number - - Hour

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

sign

sign(x) ⇒ number

Shortcut for Math.sing()

Kind: global function

ParamTypeDescription
xnumberThe variable

sin

sin(x) ⇒ number

Sine function

Kind: global function

ParamTypeDescription
xnumberThe variable

sma

sma(src, len) ⇒ TS

Simple Moving Average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

sqrt

sqrt(x) ⇒ number

Shortcut for Math.sqrt()

Kind: global function

ParamTypeDescription
xnumberThe variable

stdev

stdev(src, len) ⇒ TS

Standard deviation

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

stoch

stoch(src, high, low, len) ⇒ TS

Stochastic

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
highTSTS of high
lowTSTS of low
lennumberLength

sum

sum(src, len) ⇒ TS

Returns the sliding sum of last "len" values of the source

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberLength

supertrend

supertrend(factor, atrlen) ⇒ Array.<TS>

Supertrend Indicator

Kind: global function
Returns: Array.<TS> - - Supertrend line and direction of trend

ParamTypeDescription
factornumberATR multiplier
atrlennumberLength of ATR

swma

swma(src) ⇒ TS

Symmetrically Weighted Moving Average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput

sym

sym(x, y) ⇒ Sym

Creates a new Symbol.

Kind: global function
Returns: Sym - Argument variations: data(Array), [params(Object)] ts(TS), [params(Object)] point(Number), [params(Object)] tf(String) 1m, 5m, 1H, etc. (uses main OHLCV) Params object: { id: String, tf: String|Number, aggtype: String (TODO: Type of aggregation) format: String (Data format, e.g. "time:price:vol") window: String|Number (Aggregation window) main true|false (Use as the main chart) }

ParamTypeDescription
x*Something, depends on arg variation
y*Something, depends on arg variation

tan

tan(x) ⇒ number

Tangent function

Kind: global function

ParamTypeDescription
xnumberThe variable

tr

tr(fixnan) ⇒ TS

True Range

Kind: global function
Returns: TS - - New time-series

ParamTypeDefaultDescription
fixnanTSfalseFix NaN values

tsi

tsi(src, short, long) ⇒ TS

True strength index

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
shortnumberShort length
longnumberLong length

view

view(name, props)

Create a new View

Kind: global function

ParamTypeDescription
namestringView name
propsobjectView properties

vwma

vwma(src, len) ⇒ TS

Volume Weighted Moving Average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberlength

weekofyear

weekofyear([time]) ⇒ number

Week of year, literally

Kind: global function
Returns: number - - Week

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

wma

wma(src, len) ⇒ TS

Weighted moving average

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
srcTSInput
lennumberlength

wpr

wpr(len) ⇒ TS

Williams %R

Kind: global function
Returns: TS - - New time-series

ParamTypeDescription
lennumberlength

year

year([time]) ⇒ number

Year

Kind: global function
Returns: number - - Year

ParamTypeDescription
[time]numberTime in ms (current t, if not defined)

Released under the MIT License.