Skip to main content
A script is a list of lines that the chart runs once for every bar (see Bar-by-bar evaluation): a header, one declaration, then statements and declarations in any order.

The parts

Top level only

These may not appear inside a function, if, loop or switch:
  • indicator, strategy;
  • func, def, type and enum declarations (a syntax error elsewhere);
  • the calls that put output on the chart: plot, plotshape, plotchar, plotarrow, plotbar, plotcandle, hline, fill, bgcolor, barcolor, alertcondition. Inside a block they fail with `plot()` must be called in the global scope. (the name of the call you wrote). To draw only on some bars, put the condition in an argument instead (see Branching).
Variables, input.*, talib calls, drawings, alert and strategy.* orders may be used anywhere.

What a script cannot contain

  • import, export, method and library(): there are no libraries or modules.
  • request.*: a script reads only the symbol and interval of its chart.
  • Block comments: only // to the end of the line.
  • var and varip: use static (see Values that persist across bars).
Drawings, arrays, history and run time have fixed limits (see Limits).