Skip to content
ChartDeck ChartScript docs Account Open the terminal

Built-ins

A map of ChartScript's built-in namespaces and variables, with links to the reference, and how ta.* matches ChartDeck's own indicators bar for bar.

ChartScript comes with a large standard library: bar data, technical-analysis functions, maths, text, collections, drawings, inputs and more. Built-ins are grouped into namespaces, the part before the dot: ta.ema, math.round, str.tostring. This page is a map of those namespaces, so you know where to look. The reference manual has every function with its parameters, defaults and an example; in the editor, put the cursor on a name and press F1 to open the same text in the Reference tab.

#Bar data and core functions

These names have no namespace. They live on the global reference page.

NamesWhat they are
open, high, low, close, volumethe current bar's prices and volume
hl2, hlc3, ohlc4, hlcc4common price averages
time, time_close, timenowbar open and close time, and the current time, in milliseconds (UTC)
bar_index, last_bar_index, last_bar_timethe bar's position, and the newest bar's
year, month, dayofmonth, dayofweek, hour, minute, second, weekofyearcalendar parts of the bar time (UTC), as variables or as functions of a time
na, nz, fixnantesting and replacing missing values
int, float, bool, string, colorcasts (see Types)
indicator, librarythe declaration on line 2
plotshape, plotchar, plotarrow, plotcandle, plotbar, fill, bgcolor, barcoloroutputs (plot and hline have their own pages)
timestamp, max_bars_backbuilding a time; sizing a history buffer

#Namespaces

NamespaceForRead more
tatechnical analysis: averages, oscillators, bands, crosses, pivots, highest / lowest, bars-sincebelow
mathrounding, min / max, powers, logs, trigonometry, rolling sum, random numbers, constants such as math.pi
strtext functions and number formattingStrings and formatting
array, map, matrixcollectionsCollections
colornamed colors, color.new, color.rgb, gradients, and theme colors (color.up, color.down, color.accent, color.muted, color.text, color.grid) that follow the chart's themeColors
inputsettings the user can changeInputs
plot, hlinelines, histograms, levels, and their style constantsPlots, Levels
label, line, box, polyline, linefill, tabledrawings placed by codeDrawings, Tables
requestvalues from other timeframes and other marketsOther timeframes and markets
timeframethe chart's timeframe and timeframe arithmeticTimeframes
marketthe chart's market: market.id, market.venue, market.symbol, market.base, market.quote, market.kind, market.tick …ChartDeck data
barstatewhich kind of run this is (first, last, live, confirmed …)Execution model
sessionsession states such as first and last bar of the sessionSessions
flow, oi, funding, basis, lsr, liq, etfChartDeck data: taker flow and CVD, open interest, funding, basis and the Coinbase premium, long/short ratios, liquidations, ETF flowsChartDeck data
chartchart colors and type, chart.point for drawings, the visible range (chart.left_visible_bar_time, chart.right_visible_bar_time: the chart runs the script again when the view moves)
alertalert conditions and alert messagesAlerts
log, runtimemessages to the editor's Console, and stopping with your own errorDebugging
settings, style, i18nthe layout of the settings dialog, named styles and translations of your settings textInputs
tickerbuilding market ids, for example for Heikin Ashi bars of a requested market

Many namespaces also hold constants, such as format (format.mintick, format.volume), size, shape, location, position, xloc, yloc, extend, display, order and dayofweek.

Namespace names are reserved: you cannot call a variable ta, math or str (CS2003). The same goes for the names of ChartDeck's market-data namespaces: flow, oi, funding, basis, lsr, liq and etf (open interest, funding, basis, long/short ratios, liquidations, taker flow and CVD, ETF flows: see ChartDeck data), and book and cal.

#Not available yet

Some names exist in the library so that the editor can tell you about them, but they cannot be used yet. Using one gives CS2010 ("not available yet") instead of a confusing "not defined":

  • A few ChartDeck data names: oi.open, oi.high and oi.low (the open-interest routes serve one sample per bar: use oi.close), the multi-venue live flow flow.agg_* and the live liquidation tape liq.live_* (no bar history yet), and the economic calendar cal.*. Everything else in ChartDeck data works today.
  • A few ta.* extras (ta.fvg, ta.swings).
ChartScriptError: CS2010
//@chartscript 1
indicator("Open interest range")
plot(oi.high - oi.low)

Strategies (backtesting and orders) are not available yet either. Today the compiler refuses strategy.* names with CS2011, the code it also uses for names from other languages that ChartScript spells differently (see the table at the end of this page).

#ta and ChartDeck's built-in indicators

The ta functions use the same calculation code as ChartDeck's own indicators. That has a practical consequence: an indicator you write with ta.* gives the same numbers, bar for bar, as the built-in indicator of the same name with the same settings, including which early bars are na.

ChartDeck's official scripts show this. 68 of ChartDeck's 96 built-in indicators have one, a ChartScript version (RSI, EMA, MACD, Bollinger Bands, Supertrend, Ichimoku, pivot points, market structure, Volume, CVD, open interest, funding, liquidations, the market profile, large prints, the liquidation and order-book heatmaps and more), and each one is tested to give exactly the built-in indicator's values on every bar, or exactly its lines, boxes and labels, or, for the order-flow layers, the same data drawn by the same rules (the full list is below). You can open one with View source in a built-in indicator's settings and make your own copy to change.

ChartScriptOpen in editor
//@chartscript 1
indicator("EMA, as the built-in", { overlay: true })
const len = input.int(21, "Length", { minval: 1 })
const src = input.source(close, "Source")
plot(ta.ema(src, len), "EMA", color.orange, 2)

Add this script and ChartDeck's built-in EMA with the same length to one chart and the two lines lie exactly on top of each other.

A few conventions are worth knowing:

  • Averages start from a simple average. ta.ema and ta.rma begin with the simple average of their first length values, then continue recursively. That is how ChartDeck's built-in EMA, RSI, ATR and others work, so every place in ChartDeck shows the same values. If you need the other common convention, seeding with the first value, write ta.ema(close, 21, { seed: "first" }).
  • Missing values are honest. A window that contains na gives na, and a recursive average starts again after a gap once it has length values in a row. Your script does not need to handle this.
  • Warm-up. A 200-bar average is na for the first 199 bars of the chart, just as the built-in one is.
  • ChartDeck extras. Besides the usual set, ta has ta.ma, which takes the average type as text (the 11 types of ChartDeck's moving-average indicators: "sma", "ema", "wma", "hma", "alma", "kama", "zlema", "vwma", "dema", "tema", "rma"), plus ta.kama, ta.zlema, ta.dema, ta.tema, ta.squeeze, ta.wavetrend and ta.heikin_ashi. Pair ta.ma with input.ma_type for a ready-made average selector:
ChartScriptOpen in editor
//@chartscript 1
indicator("Any average", { overlay: true })
const kind = input.ma_type("ema", "Average type")
const len = input.int(50, "Length", { minval: 1 })
plot(ta.ma(kind, close, len), "Average", color.accent, 2)

#Built-in variables with a qualifier

Built-ins carry qualifiers like any value. Bar data (close, time, bar_index, barstate.*) is series. Facts about the chart that do not change during a run (market.tick, market.id, timeframe.period, timeframe.multiplier, chart.bg_color) are simple, which means you can pass them where a simple value is required, such as the length of ta.rsi.

#Names you may know from elsewhere

If you have written indicators in other charting script languages, a few names differ on purpose:

ElsewhereIn ChartScript
symbol information (mintick, tickerid …)market.*: market.tick, market.id
security requestsrequest.tf (same market) and request.market (another market)
intrabar persistence keywordlive state
alert conditions / alert callsalert.on / alert.send

The Migrating section covers converting existing scripts in detail.

#All official scripts

Open any of them with View source in the built-in indicator's settings; Make a copy to edit gives you your own copy (MPL-2.0).

GroupOfficial scripts
Averages and trendMoving average, EMA, SMA, MACD, Supertrend, ADX / DMI, Ichimoku cloud, Parabolic SAR, Heikin Ashi (smoothed), TRIX, Linear regression channel
OscillatorsRSI, Stoch RSI, Stochastic, CCI, Williams %R, Momentum, Rate of change (ROC), Awesome oscillator, WaveTrend, Squeeze momentum
Volatility and bandsBollinger Bands, Bollinger %B, Bollinger bandwidth, Keltner channels, Donchian channels, Average true range (ATR), Chandelier exit
VolumeVolume, On-balance volume (OBV), Money flow index (MFI), Chaikin money flow (CMF), VWAP, VWAP + deviation bands, Anchored VWAP
ProfilesFixed range volume profile, Anchored volume profile, Volume profile (approx.), Market profile (TPO)
Levels and structurePivot points, Previous day / week / month levels, Session ranges, Zigzag, Williams fractals, Market structure (BOS / CHoCH), Fair value gaps, Order blocks, Liquidity sweeps, Divergences, Auto Fibonacci retracement
Order flow (ChartDeck data, trade prints, order-book data)CVD, Volume delta, Bar statistics, Large prints, Order book heatmap
Derivatives (liquidation data)Open interest, OI delta, Aggregated open interest, OI / price regime, Funding rate, Aggregated funding, Perp/spot basis, Coinbase premium, Long/short ratio, Liquidations, Liquidation levels, Liquidation heatmap
FlowsETF net flows

The order-flow layers (Market profile, Large prints, the liquidation and order-book heatmaps) read live or modeled data that the built-in studies also draw with screen-pixel rules (label lanes, bubbles spread inside a bar); their scripts read the same data and follow the same rules where a script can, and each script's header says how it draws.

The ChartScript documentation is in English for now; translations will follow.