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.
| Names | What they are |
|---|---|
open, high, low, close, volume | the current bar's prices and volume |
hl2, hlc3, ohlc4, hlcc4 | common price averages |
time, time_close, timenow | bar open and close time, and the current time, in milliseconds (UTC) |
bar_index, last_bar_index, last_bar_time | the bar's position, and the newest bar's |
year, month, dayofmonth, dayofweek, hour, minute, second, weekofyear | calendar parts of the bar time (UTC), as variables or as functions of a time |
na, nz, fixnan | testing and replacing missing values |
int, float, bool, string, color | casts (see Types) |
indicator, library | the declaration on line 2 |
plotshape, plotchar, plotarrow, plotcandle, plotbar, fill, bgcolor, barcolor | outputs (plot and hline have their own pages) |
timestamp, max_bars_back | building a time; sizing a history buffer |
#Namespaces
| Namespace | For | Read more |
|---|---|---|
ta | technical analysis: averages, oscillators, bands, crosses, pivots, highest / lowest, bars-since | below |
math | rounding, min / max, powers, logs, trigonometry, rolling sum, random numbers, constants such as math.pi | |
str | text functions and number formatting | Strings and formatting |
array, map, matrix | collections | Collections |
color | named 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 theme | Colors |
input | settings the user can change | Inputs |
plot, hline | lines, histograms, levels, and their style constants | Plots, Levels |
label, line, box, polyline, linefill, table | drawings placed by code | Drawings, Tables |
request | values from other timeframes and other markets | Other timeframes and markets |
timeframe | the chart's timeframe and timeframe arithmetic | Timeframes |
market | the chart's market: market.id, market.venue, market.symbol, market.base, market.quote, market.kind, market.tick … | ChartDeck data |
barstate | which kind of run this is (first, last, live, confirmed …) | Execution model |
session | session states such as first and last bar of the session | Sessions |
flow, oi, funding, basis, lsr, liq, etf | ChartDeck data: taker flow and CVD, open interest, funding, basis and the Coinbase premium, long/short ratios, liquidations, ETF flows | ChartDeck data |
chart | chart 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) | |
alert | alert conditions and alert messages | Alerts |
log, runtime | messages to the editor's Console, and stopping with your own error | Debugging |
settings, style, i18n | the layout of the settings dialog, named styles and translations of your settings text | Inputs |
ticker | building 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.highandoi.low(the open-interest routes serve one sample per bar: useoi.close), the multi-venue live flowflow.agg_*and the live liquidation tapeliq.live_*(no bar history yet), and the economic calendarcal.*. Everything else in ChartDeck data works today. - A few
ta.*extras (ta.fvg,ta.swings).
//@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.
//@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.emaandta.rmabegin with the simple average of their firstlengthvalues, 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, writeta.ema(close, 21, { seed: "first" }). - Missing values are honest. A window that contains
nagivesna, and a recursive average starts again after a gap once it haslengthvalues in a row. Your script does not need to handle this. - Warm-up. A 200-bar average is
nafor the first 199 bars of the chart, just as the built-in one is. - ChartDeck extras. Besides the usual set,
tahasta.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"), plusta.kama,ta.zlema,ta.dema,ta.tema,ta.squeeze,ta.wavetrendandta.heikin_ashi. Pairta.mawithinput.ma_typefor a ready-made average selector:
//@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:
| Elsewhere | In ChartScript |
|---|---|
symbol information (mintick, tickerid …) | market.*: market.tick, market.id |
| security requests | request.tf (same market) and request.market (another market) |
| intrabar persistence keyword | live state |
| alert conditions / alert calls | alert.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).
| Group | Official scripts |
|---|---|
| Averages and trend | Moving average, EMA, SMA, MACD, Supertrend, ADX / DMI, Ichimoku cloud, Parabolic SAR, Heikin Ashi (smoothed), TRIX, Linear regression channel |
| Oscillators | RSI, Stoch RSI, Stochastic, CCI, Williams %R, Momentum, Rate of change (ROC), Awesome oscillator, WaveTrend, Squeeze momentum |
| Volatility and bands | Bollinger Bands, Bollinger %B, Bollinger bandwidth, Keltner channels, Donchian channels, Average true range (ATR), Chandelier exit |
| Volume | Volume, On-balance volume (OBV), Money flow index (MFI), Chaikin money flow (CMF), VWAP, VWAP + deviation bands, Anchored VWAP |
| Profiles | Fixed range volume profile, Anchored volume profile, Volume profile (approx.), Market profile (TPO) |
| Levels and structure | Pivot 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 |
| Flows | ETF 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.