Skip to main content
A Lipi statement ends at the end of its line. There is no statement separator character, and a block with statements is always written over several lines (an empty {} is accepted). This page lists where a statement may continue on the next line and the layouts the compiler refuses, with the message it gives for each.

The first line

Every Lipi v2 script starts with the line //@lipi=2. A script without it is read as a Lipi v1 script, an older language with other rules, so it may fail or behave differently. The next statement declares the script, once: indicator(...) for an indicator, strategy(...) for a strategy (see Strategies and backtesting).
A script with no declaration, or with two, is refused: Script must declare exactly one of indicator(), strategy(), or library(); found 0 ((none)).

One statement to a line

Put each statement on its own line. A semicolon does not separate statements:
The compiler says: extraneous input ’;’ expecting {<EOF>, NEWLINE}. Write a = close and b = open on two lines. When several lines are joined this way, the compiler reports only one of them, so fix them all before checking again. Indentation does not matter to the compiler; indent blocks by four spaces for readers. Names are case-sensitive: x and X are two variables. A comment starts with // and runs to the end of the line, on a line of its own or after a statement.

Blocks

if, else, loops, switch, function bodies, type and enum use braces. The opening brace stays on the line that starts the block, and the block’s statements go on the lines after it, never on the same line as a brace:
The compiler says: mismatched input ‘x’ expecting {’}’, NEWLINE}. Write it over three lines:
else may follow the closing brace on the same line, as above, or start the next line. The opening brace may not move to the next line: if close > open followed by { on its own line is refused with extraneous input ‘\n’ expecting ’{’.

Continuing a long statement

A statement may continue on the next line where the line clearly cannot end:
  • after a comma or an opening parenthesis, inside the arguments of a call;
  • after an operator (+, -, *, /, and, or, a comparison), at the end of the line;
  • after =, := or =>;
  • after the ? and the : of a conditional expression.
A line may not start with an operator: the line before it is then a complete statement, and the operator has nothing on its left.
The compiler says: no viable alternative at input ‘\n+’. Move the operator to the end of the line before.