Custom indicators

Open the LabScript editor from the chart (or ƒx Indicators → My scripts → New script). You can paste an open-source indicator written in Pine-style syntax (v5 or v6), or write JavaScript. In JavaScript, a script is the body of a function that returns the lines to draw.

Data and helpers

Name Meaning
open, high, low, close, volume, time arrays, oldest candle first
hl2, hlc3 (high + low) / 2 and (high + low + close) / 3
sma(src, n), ema(src, n), rma(src, n), wma(src, n) moving averages
rsi(src, n), stdev(src, n), change(src, n)
highest(src, n), lowest(src, n) highest / lowest of the last n
atr(n) average true range

Values that cannot be computed yet (the first candles) are null and are not drawn.

Return one line or several

// one line
return ema(close, 21)
// several lines, each with its own colour
const fast = ema(close, 12)
const slow = ema(close, 26)
return { macd: fast.map((f, i) => f - slow[i]), zero: close.map(() => 0) }

Choose Over the candles for price-like lines, or In its own pane for oscillators. Press Test to run it on the chart's data, then Save.

Safety

Scripts run in your browser inside a sandbox with no access to the internet, your account or saved data, and are stopped after 3 seconds. They cannot place trades.

The library

Open the indicator library to browse indicators other traders published. Read the code, then press Add to my scripts. To share yours, open it in the editor and press Publish. Missing something? Post it in Requests and vote for ideas you like.