ScriptingReferenceKeyword index

Keyword index

The grammar reserves 33 words. 12 of them carry a syntax template in the language contract; the rest are control-flow and declaration words that the contract does not describe but the parser accepts.

Documented in the contract

KeywordSyntaxDescription
andexpr0 && expr1 | expr0 and expr1True when both of its operands are true. It has a symbol spelling as well, and the two are the same token to the lexer. There is no difference in behaviour to weigh up, so pick one spelling for a script and keep to it.
defdef <function_name>(<data_type> <param_name> [= <default_value>], ...) { <function_body> } func <function_name>(<data_type> <param_name> [= <default_value>], ...) => <expression>Opens a function declaration. It is interchangeable with func, and both are optional — a declaration may begin with either or with neither. All three spellings declare the same thing, so which you use is a house-style decision.
enumenum <enum_name> { <enum_field> [= <title>] ... }Declares an enum of your own, as a braced block of members, one per line. A member may carry something after =. Note what that is: a title, not a value.
funcfunc <function_name>(<data_type> <param_name> [= <default_value>], ...) { <function_body> } func <function_name>(<data_type> <param_name> [= <default_value>], ...) => <expression>The other spelling for opening a function declaration. It declares exactly what def declares. A body is either a braced block or a single expression after an arrow, and the arrow form also accepts a tuple, which is how a function returns more than one value.
ifif <condition> { <true_block> } else if <condition> { <true_block> } else { <false_block> }Chooses which block of statements runs. Any number of else if arms may follow, and one else arm may close it; both are optional. It is a statement, not an expression: it decides which block runs rather than producing a value. And it opens a scope of its own, which is why a chart-output call placed inside one is rejected — put the condition in an argument instead, and leave the call at the top level.
intraintra <data_type> <variable_name> = <expression>The second of the two persistence keywords the grammar accepts, and the only other one. A value declared intra is kept while the current bar is still forming and is repeatedly recalculated, and it is reset the moment a new bar starts. Use it to carry something across recalculations of one bar; use static to carry something across bars. That is the whole difference between the two. static keeps its store for as long as the script runs, and intra has its store cleared at every new bar.
not!expr0 | not expr0Negates the expression that follows it. The third of the three logical operators with two spellings, and the only one that takes a single operand rather than two.
orexpr0 || expr1 | expr0 or expr1True when either of its operands is true. Like and, it has a symbol spelling that lexes to the same token.
returnreturn <expression>Hands a value back from a braced function body. It takes an expression. A tuple is written as a bracketed list, so a function can return several values at once. The arrow body form needs no return — the expression after the arrow is the result.
staticstatic <data_type> <variable_name> = <expression>Declares a value that survives from one bar to the next. Without it, a declaration is made again on every bar, because your script is evaluated once per bar. Reassign a static value with := and the new value carries forward. Its store is never cleared while the script runs, which is what separates it from intra. This is the only spelling: a declaration opening with var does not compile, and that mistake is common enough to check first when a declaration is rejected.
typetype <type_name> { <data_type> <field_name> [= <default_value>] ... }Declares an object type of your own: a name, then a braced block with one typed field per line. A field may carry a default value, and at least one field is required. A data type in a field may carry type arguments in angle brackets. Which types accept them is not documented, so no example is offered.
whilewhile <condition> { ... break ... continue ... }Repeats a block for as long as a condition holds. break leaves the loop and continue starts the next pass. Give it an exit you control. The interpreter enforces its own resource limits and reports a diagnostic when one is passed rather than returning a partial result, and a break written outside a loop is rejected rather than ignored.

Accepted by the grammar

These are reserved words the parser accepts. They carry no contract entry, which is why they are absent from the current reference.

Keyword
bool
break
case
color
const
continue
default
else
false
float
for
in
int
na
series
simple
step
string
switch
to
true
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade