Skip to main content
Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Entries: 24

and (keyword)

Definition True 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. Syntax
Example

break (keyword)

Definition Leaves the innermost for or while loop at once. Syntax
Example

case (keyword)

Definition Starts one block of a switch: case <value>: runs its block when the value of the switch equals <value>. The first case that matches runs, and the switch ends: the next case does not run. A case takes one value, so case 1, 2: is a syntax error. The value must have the type of the switch value (an int fits a float switch); otherwise the compiler stops with “Case condition is not compatible with switch condition.” and the two types. Syntax
Example

const (keyword)

Definition A qualifier written before the type of a parameter of your own function. A const parameter takes only a value that is known when the script is compiled, such as 2.0 or 10 * 2. A value that changes, such as close, is refused with “Cannot call <function> with argument <name>=<value>. An argument of series float type was used but a const float is expected.” The word is not allowed before a variable declaration. Syntax
Example

continue (keyword)

Definition Skips the rest of the current pass of the innermost for or while loop and starts the next pass. Syntax
Example

def (keyword)

Definition Declares a type function (method on a type): the first parameter is the receiver — its declared type is the type the method belongs to. You must list at least one parameter (the receiver). Use func (or a declaration with no leading keyword) for ordinary functions, including func name() => … with zero parameters. def is not interchangeable with func when the parameter list is empty. Syntax
Example

default (keyword)

Definition Runs its block when no case of the switch matches. A switch takes at most one default: a second one stops the compiler with “Only one default case is allowed in a switch statement.” Syntax
Example

else (keyword)

Definition Runs a block when the condition of the if before it is false. It follows the closing } of the if block, on the same line or on the next, and can be chained as else if <condition> { ... }. Syntax
Example

enum (keyword)

Definition 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. Syntax
Example

for in (keyword)

Definition Loops over each element of an array. The name after in must be a variable that holds an array; the loop variable is assigned the current element on every pass. break leaves the loop and continue starts the next element. Like while and for ... to, the loop body is a braced block. Syntax
Example

for to (keyword)

Definition Counts from a start value to an end value, using a counter variable. The end value is included (for 1 to 5 the counter takes 1, 2, 3, 4 and 5), except when the start and the end are equal: then the body does not run at all. Both bounds are expressions; the counter is a simple identifier assigned on each pass. An optional step expression changes the increment (negative steps count down). break leaves the loop and continue starts the next iteration. Syntax
Example

func (keyword)

Definition Declares an ordinary user function (not a type method). The parameter list may be empty, e.g. func pi() => 3.14159. Use def when the first parameter is a typed receiver for a type function; use func for everything else. A body is either a braced block or a single expression after an arrow; the arrow form may return a tuple for multiple values. Syntax
Notes
  • A function body may call a drawing function such as label.new; it compiles. The chart-output calls listed under if, for example plot, are rejected inside a function.
  • A braced body with no return is valid: the function returns nothing. A function that returns a value must end every path in a return; otherwise the compiler says “The <name>() function is missing return statement.”
Example

if (keyword)

Definition 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. Syntax
Notes
  • A drawing call such as label.new compiles inside an if block. The chart-output calls plot, plotshape, plotchar, plotarrow, plotbar, plotcandle, bgcolor, barcolor, hline, fill and alertcondition are rejected there; alert is accepted.
  • switch <value> { case <value>: ... default: ... } also chooses a block and compiles.
Example

intra (keyword)

Definition The second of the two persistence keywords the grammar accepts, and the only other one. A value declared intra is kept across the repeated runs of the bar that is still forming, and is cleared when a new bar starts: the next bar starts from the initializer again. Use it to carry something across recalculations of one bar; use static to carry something across bars. The difference from static is when a value is committed, not only how long it lives. A static value is stored when a bar is confirmed, so each run of a forming bar starts from the value stored when the last bar closed; an intra value is kept between the runs of the same bar and dropped when the next bar starts. On historical bars a bar usually runs once, so intra then behaves like an ordinary variable; a strategy with calc_on_order_fills=true runs a historical bar again after a fill, and an intra value carries across those runs until the bar finishes. Syntax
Example

not (keyword)

Definition Negates 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. Syntax
Example

or (keyword)

Definition True when either of its operands is true. Like and, it has a symbol spelling that lexes to the same token. Syntax
Example

return (keyword)

Definition Hands a value back from a braced function body. It takes an expression, which may be left out: a bare return ends a function that returns no value, and the result of such a function cannot be assigned (“Cannot assign void value.”). 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. Syntax
Example

series (keyword)

Definition A qualifier written before the type of a parameter of your own function. A series parameter takes a value that may change from bar to bar, and any value of the other qualifiers. A parameter written with no qualifier is series: func passthru(float k) => k returns a series float, which a plot(linewidth=...) argument refuses. The word is not allowed before a variable declaration. Syntax
Example

simple (keyword)

Definition A qualifier written before the type of a parameter of your own function. A simple parameter takes a value that is known on the first bar and stays fixed, such as syminfo.mintick, and any const or input value. A value that changes from bar to bar, such as close, is refused with “Cannot call <function> with argument <name>=<value>. An argument of series float type was used but a simple float is expected.” The word is not allowed before a variable declaration. Syntax
Example

static (keyword)

Definition 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. The initializer runs when execution first reaches the declaration and no value has been stored for it, which is ordinarily the first bar. Reassign a static value with := and the new value carries forward, but a change is kept only when the bar is confirmed: while a bar is still forming and the script runs again on each update, every run starts from the value stored when the last bar closed, and what the earlier runs of that bar changed is discarded. Its store is never cleared while the script runs, which is what separates it from intra. Syntax
Example

step (keyword)

Definition The optional increment of a counted for loop: for i = 0 to 10 step 2. step is a reserved word. It cannot be used as the name of a variable. Syntax
Example

switch (keyword)

Definition Chooses one block by the value of an expression. Each case <value>: starts a block, and default: runs when no case matches. switch is a statement. It does not produce a value, so it cannot be assigned. Do not use it inside a function body. A switch there passes the editor’s check but is refused when the script is added to the chart, with the bare message Not Implemented; a function that holds a switch but is never called compiles. Use if and else if inside functions. A function whose switch returns in every case and in default, with no return after it, fails both checks with “The f() function is missing return statement.”, and adding a return after it only brings back Not Implemented on the chart. Syntax
Example

type (keyword)

Definition 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 field’s data type may carry type arguments in angle brackets, as in array<float> xs. Syntax
Notes
  • A user-defined type can be the type argument of an array: array.new<Zone>() compiles when Zone is declared with type.
  • A type block with no field is rejected.
  • Create an instance with <type_name>.new(...), giving the arguments by position or by field name: Zone.new(high, 0) and Zone.new(top=high, touches=0) are both accepted. Calling the type name without .new, as in Zone(high, low), is rejected.
  • A field is read as z.top and written with :=, as in z.touches := z.touches + 1.
Example

while (keyword)

Definition 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. A loop that passes the script’s resource limits stops with a diagnostic rather than a partial result, and a break outside a loop is rejected. Syntax
Notes
  • The counted loop for i = 0 to <n> { ... }, with an optional step <m>, and the iteration loop for x in <array> { ... } also compile.
Example