Skip to main content
Skip to main content

Functions overview

If indicators are classic studies (RSI, MACD), functions are the chart’s formula layer — they take one or more numeric series and return a new series.

There is no “market logic” built in. You supply the inputs.

Loading chart…
Functions often consume indicator outputs — add the source indicator first.

Why functions exist

Without functionsWith functions
Only pre-built studiesCustom math on any line
Hard to shift or combine linesDISPLACE, IGLUE, SUM in the UI
Strategies limited to defaultsFeed strategies your own series

Think spreadsheet formulas tied to bar timestamps.

Functions vs indicators vs strategies

flowchart TB
subgraph ind ["Indicators"]
I1["Read OHLC"]
I2["Draw MA, RSI, bands"]
end
subgraph fn ["Functions"]
F1["Read any series"]
F2["Transform / combine"]
end
subgraph st ["Strategies"]
S1["Read series"]
S2["Emit Buy / Sell signals"]
end

ind --> fn
fn --> st
ind --> st
TypeOutputExample
IndicatorLines, bands, histogramsEMA → orange line
FunctionNumeric seriesDISPLACE(EMA) → shifted EMA
StrategySignal markersCROSS(EMA, SMA) → buy/sell arrows

All 10 built-in functions

KeyDisplay nameOne-line purpose
HIGHESTHighestRolling highest high (or chosen series)
LOWESTLowestRolling lowest low
FIBONACCIFibonacciRolling Fib levels from high/low
DISPLACEDisplaceTime-shift a series + optional offset
IGLUEIndicator GlueAdd / subtract / multiply / divide two series
IMODIndicator ModifierApply math between a series and a constant
IFIFThree-way compare: A vs B → X, Y, or Z
SUMSumAdd up to 10 conditional inputs
AVERAGEAverageMean of up to 10 inputs (skips gaps)
1x1/xReciprocal of a series

Full defaults and pane column: Function catalog.

Two tiers: plug-and-play vs wiring

Tier 1 — works on price out of the box

These default to main-series high or low:

chart.addScript("HIGHEST");
chart.addScript("LOWEST");
chart.addScript("FIBONACCI");

They draw as overlays on the main chart.

Tier 2 — needs a source series

Add the producer first, then point the function at its output in settings or code:

FunctionMain inputTypical wiring
DISPLACEDSERIESOutput of EMA
IGLUETwo seriesEMA + SMA
IMODSeries + constantRSI × 2
IFVAL_A, VAL_BEMA vs SMA (conditional mode)
SUM / AVERAGEUp to 10 inputsSeveral indicator lines
1xOne seriesInvert any positive series

Walkthrough: Programmatic wiring.

Input types you will see

Input typeUI behavior
seriesDropdown of Symbol.Field references
integer / doublePeriods, offsets, constants
listOperation picker (Add, Multiply, …)
conditionalToggle Number vs Series per value

Series and panels explains dropdown labels and seriesId:field format.

Panel behavior

KeyDefault pane
Overlay on main chartHIGHEST, LOWEST, FIBONACCI, DISPLACE, IGLUE, IMOD
New panel belowIF, SUM, AVERAGE, 1x

Override in the Panel dropdown like any indicator.

Visibility

Functions appear under Chart settings → On chart → Functions with plot and scale toggles — Chart settings.

API: setChartFunctionVisibility, setChartFunctionPriceTagVisibility, removeChartFunction.

Example pipeline (beginner-friendly)

Goal: shaded regime line — 1 when EMA > SMA, -1 when below.

chart.addScript("EMA");
chart.addScript("SMA");

const emaRef = getSeriesReference(chart, "EMA");
const smaRef = getSeriesReference(chart, "SMA");

const ifScript = structuredClone(chart.getScripts().IF);
ifScript.inputs.VAL_A.value = { type: "series", value: emaRef };
ifScript.inputs.VAL_B.value = { type: "series", value: smaRef };
ifScript.inputs.VAL_X.value = { type: "double", value: 1 };
ifScript.inputs.VAL_Y.value = { type: "double", value: 0 };
ifScript.inputs.VAL_Z.value = { type: "double", value: -1 };

chart.addScript("IF", ifScript);

(getSeriesReference — copy from Programmatic wiring.)

What is next?