Welcome to ChartScript
ChartScript is ChartDeck's scripting language for your own indicators. Learn what it does, how a script runs, and where to start.
ChartScript is the language you use to write your own indicators in ChartDeck. You describe what to calculate and what to draw, and ChartDeck runs your script on the chart: it updates live as new trades arrive, works on every market and timeframe you can open, and saves with your layouts like any built-in indicator.
You do not need to be a programmer to start. A useful script can be three lines long, and the editor checks your code as you type, explains every built-in name and offers fixes for common mistakes.
#What you can build
With ChartScript you can:
- Draw lines and bands over the price: moving averages, envelopes, channels, VWAP-style levels, ribbons.
- Build oscillators in their own pane: momentum, RSI-style indicators, histograms, with level lines and filled zones.
- Mark events on the chart: shapes and characters above or below bars, colored backgrounds, colored candles.
- Draw objects: labels, lines, boxes, polylines and tables that you create and move from code.
- Read other timeframes and markets: compare the chart with a higher timeframe trend, or with another coin.
- Define alert conditions that describe when something interesting happens.
- Give your indicator settings: inputs become the familiar Inputs, Colors and Style tabs of the settings dialog, so you (and anyone you share it with) can tune it without touching the code.
When a script is ready you can keep it private, or publish it to the Community, either with its source open for others to learn from or protected so only the result is shared.
#How a script runs
A script runs once for every bar on the chart, starting with the oldest bar and moving forward to the newest. On each bar, names such as close and high hold that bar's values, and anything you plot becomes one point of a line. That is why a script reads like a calculation for a single bar: ChartDeck repeats it for you across the whole history.
When the newest bar is still open, the script runs again as new prices arrive, so the last point of each line moves with the market. When the bar closes, its values are final. The execution model explains this in detail, including the tools that keep values from one bar to the next.
Your own scripts run in your browser. The editor compiles your code on your device and runs it in a sandbox next to the chart, so a script you are writing costs nothing on the server and updates as fast as your chart does. On a phone a script runs on fewer bars (at most 2,000) to stay responsive.
Protected Community scripts run on ChartDeck's servers. When you add a script whose author keeps the source private, ChartDeck runs it on its own servers and sends your chart only the values to draw, never the code. Every bar close is always shown; how often the open bar updates depends on your plan (see Limits).
#Your first script
Here is a complete script. It draws a 20-bar simple moving average over the price:
//@chartscript 1
indicator("My first average", { overlay: true })
const length = input.int(20, "Length", { minval: 1 })
plot(ta.sma(close, length), "Average", color.accent, 2)Line by line:
//@chartscript 1says which version of the language the script uses. Every script starts with it.indicatornames the script.overlay: truedraws it on the price instead of in a pane of its own.input.intcreates a setting called Length with a default of 20. It appears in the indicator's settings dialog.ta.smaaverages the lastlengthcloses, andplotdraws the result as a line in the theme's accent color, 2 pixels wide.
Press Open in editor on the example to try it, then follow Your first script to save it and put it on a chart.
#Where to go next
The documentation is split into sections. Read Getting started first, then dip into the rest as you need it.
Getting started: using the editor and managing your scripts.
- Your first script: open the editor, start from a template, save and add to a chart.
- Editor tour: every part of the editor, its tabs and shortcuts.
- Saving and versions: every save is a version you can compare and restore.
- Adding to a chart: the settings dialog, the legend and layouts.
- Preview on chart: see changes on the chart while you type.
- Publishing: share a script with the Community.
Primer: learn by building.
- First indicator and Next steps: the basics, slowly.
- Tutorials: a moving average ribbon, RSI divergence marks, volume spikes, session highs and lows, a multi-timeframe trend and a dashboard table.
Language: how ChartScript works.
- Execution model: bar by bar, history and the live bar.
- Series and qualifiers and Types: what kind of value each name holds.
- User types, enums and methods: your own data structures.
- Variables, Operators, Conditionals, Loops and Functions.
- Collections: arrays, maps and matrices.
- Strings and formatting, Built-ins and Libraries.
Concepts: the ideas behind charts and data.
- Bars and time, Sessions and Timeframes.
- Other timeframes and markets and Repainting.
- Inputs, The settings dialog, Alerts and Strategies (not available yet).
- Non-standard charts and ChartDeck data.
Drawing on the chart: everything a script can show.
- Plots, Fills, Levels and Colors.
- Text and shapes, Drawings and Tables.
- Background color and Bar coloring.
Writing scripts: good habits and sharing.
- Style guide, Debugging, Performance and Profiling.
- Publishing and licenses, Visibility and protection and Community rules.
Migrating: bring scripts from other charting platforms.
Look things up
- Reference manual: every built-in name with its signature and a short explanation.
- Error messages: every
CScode, what it means and how to fix it. - FAQ, Limits and Release notes.
#Plans
ChartScript is included on every plan, Beginner, Plus, Pro and Elite, as soon as you sign in. The language is the same on every plan. What differs is how many scripts you keep, how many versions of each, how large a script can be, how many bars it runs on, how many other timeframes and markets it can read, and how often protected Community scripts update. Limits lists every number.
#About these docs
The documentation is in English only for now. Translations into the other languages of ChartDeck will follow later. The names in the language itself (close, ta.ema, plot and so on) are English in every language and never change.