TradingCharts

ChartScriptOverview

ChartScript lets you write your own indicators and strategies in a Pine-compatible language, check them with Verify and run them on any chart.

Inputs

Inputs are the values your users edit from the chart's Settings dialog. Declaring an input returns its current value — your script never cares whether the user has opened the dialog…

Alerts

A ChartScript script talks to the alert system in two ways:

Bar States

barstate.* is a namespace of booleans that describe where the script currently is in the per-bar loop.

Chart Information

The runtime exposes everything the script knows about the chart it is running on through three namespaces: syminfo.*, chart.*, and timeframe.*.

Strings

Strings are 16-bit Unicode. Both 'single' and "double" quote delimiters work; both support the same escape sequences:

Time

All times inside ChartScript are expressed as epoch milliseconds, UTC — a 64-bit integer. Chart display formats are a presentation concern; the script works with raw numbers.

Timeframes

A timeframe names the bar size: "5" (5 minutes), "60" (1 hour), "D" (1 day), "W" (1 week), "M" (1 month), or seconds ("1S", "30S").

Sessions

A session is a time window within a trading day. ChartScript represents a session as a string in HHMM-HHMM form, optionally followed by a day-of-week filter :1234567 (1 = Sunday, 7 =…

Other Timeframes and Data

The request.* family lets a script reach outside its own symbol or timeframe: a higher-timeframe RSI on an intraday chart, a benchmark index's return, a stock's dividend / earnings…

Non-Standard Chart Data

ChartScript indicators run on whatever chart type the user has selected. On candle / bar / line charts the series values match the raw symbol data. On non-standard chart types…

Strategies

A strategy is an indicator that also places orders. The runtime maintains a position, matches entries against exits, applies commission and slippage, and feeds a backtest report.

Libraries

A library is a reusable module of exported functions, types, and enums. Scripts import a library by owner, name, and version — version-pinned so a library update never silently breaks…

Repainting

A script repaints when values displayed on a confirmed historical bar change *after* that bar has closed. Repainting is the main source of "my strategy was profitable in backtest but…

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.

Plots

plot() is the main way to display a numeric series. It appears once at script scope and the host renders a point per bar from the value you supply.

Colors

Colors are 24-bit RGB values, optionally with an 8-bit alpha channel.

Fills

A fill is a tinted region between two plots or two hline levels.

Levels

Horizontal levels mark constant prices (overbought bands, round numbers, average entry) that span the whole chart pane.

Lines and Boxes

Lines, boxes, and polylines are drawing objects: you create them with .new(), hold the returned reference, and later modify or delete it.

Backgrounds

bgcolor() tints the background of each bar. It is the right tool for visualising sessions, filter windows, or regime labels — any colour-only, per-bar state.

Bar Coloring

barcolor() recolours the chart's candles themselves. The host repaints the body and wick in the colour you supply; na leaves the candle in its default colour.

Bar Plotting

Two declarative calls render *synthetic candles* from your own OHLC series:

Text and Shapes

ChartScript exposes three declarative shape plotters (plotshape, plotchar, plotarrow) and one drawing primitive (label.new).

Tables

A table is a floating UI element pinned to one of the chart's nine positions. It is the right tool for always-visible, grid-shaped summaries (strategy report, regime read-out, session…

Debugging

Four channels help you understand what a running script is doing: the log.* family and the Logs pane (filters, source jump, scroll to bar), visible plots, the Problems panel, and Profiler mode.

Limitations

Every hard limit the platform enforces — source size, history depth, compute budgets, drawing caps, collection sizes, backtest and alert limits — with the current values.

Profiling and Optimization

Profiler mode shows per-line runtime share and execution counts on the live execution; the patterns that follow keep a per-bar script inside its compute budget.

Publishing

A script becomes usable to someone else — including yourself on a different chart — only after it is published. Publishing an indicator or strategy stores a version on the server and…

Style Guide

Conventions that make a ChartScript source readable, diffable, and reviewable.

What Is Not Supported

The Pine Script v6 built-ins the platform does not provide — variables, functions and constants that fail to compile or always return na — and what to use instead.

Undeclared Identifier

The compiler saw a name it does not recognise.

Expected End of Line

Something followed a complete statement before the newline — usually a stray token the parser cannot interpret.

Expression Statement Has No Effect

An expression at script scope that doesn't do anything — a bare identifier, a bare arithmetic expression, a function call whose return is thrown away.

Drawing-Object Caps

The script tried to create more lines / labels / boxes / polylines than its declaration allows.

Compute Budget Exceeded

A computation ran past its wall-clock budget (2 s per live tick, 10 s for a full recompute). What the budgets are, how pacing avoids the error, and the usual causes.