TradingCharts

ChartScript Language

Every building block of ChartScript — the series-first execution model, types and qualifiers, declarations, control flow, functions, and collections.

Script Structure

A ChartScript source follows this general shape:

Type System

Every value in ChartScript has two tags: a type (what shape the value has) and a qualifier (how often it changes). The compiler uses both to decide where a value may be used.

Identifiers

An identifier is the name of a variable, constant, function, parameter, type, enum, library import, or input id.

Operators

ChartScript operators are grouped by purpose below. Precedence is listed in the final section.

Variable Declarations

ChartScript has three declaration forms. What differs between them is *when* the initializer runs and whether the value survives from bar to bar (and from tick to tick).

Declaration Statements

Every script contains exactly one declaration call. It identifies the kind of script and fixes properties that cannot change during a run.

Execution Model

A ChartScript script runs once per bar across the chart's visible history (and continues per-tick on the forming bar). Understanding this loop is essential — it is why every variable is…

Conditional Structures

ChartScript supports three forms of conditional selection: the ternary operator, if statements, and switch statements. All three can also be *expressions* that yield a value.

Loops

Loops iterate at the current bar. They are used for walks over arrays, index-based scans, or integer counters — not for reaching back through historical bars (use [n] for that).

User-Defined Functions

Functions let you factor a repeated calculation behind a name.

Methods

A method is a user-defined function that can be called with the . syntax on a receiver type. Methods are not a new language feature — they are a call-site convenience that chains…

Objects

A user-defined type (UDT) groups related values under one name. UDTs are the structured-data primitive of ChartScript — any collection of fields that belong together should be a UDT…

Enums

An enum declares a small, closed set of named string values. Enums are the right tool for category inputs (Up, Down, Flat) and for mode flags you compare against by name.

Arrays

An array is an ordered, mutable, zero-indexed collection of values of one type.

Maps

A map is a mutable key/value container. Keys are unique, insertion order is preserved for iteration.

Matrices

A matrix is a rectangular, two-dimensional, mutable collection of values of one type.

Built-Ins

This page is a map, not a full reference — each sub-area has its own page with signatures and examples.

Built-In Reference

Every built-in function the ChartScript compiler accepts — 449 functions grouped by namespace, with their signatures. Generated from the compiler and the Pine v6 reference on 2026-10-16.