> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Statements and lines

> One statement to a line, where a long statement may continue on the next line, how blocks are written, and the forms the compiler refuses.

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](https://gocharting.com/docs/scripting/strategies/overview.md)).

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close")
plot(close)
```

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:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Two statements")
a = close; b = open
plot(a - b)
```

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:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("One-line block")
float x = 0
if close > open { x := 1 }
plot(x)
```

The compiler says: mismatched input 'x' expecting \{'}', NEWLINE}. Write it over three lines:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Block over three lines")
float x = 0
if close > open {
    x := 1
} else {
    x := -1
}
plot(x)
```

`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.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Long statements", overlay=true)
rising = close > open and
  volume > talib.sma(volume, 20)
level = rising ?
  high :
  low
label.new(bar_index, level,
  text="Level",
  color=color.blue)
```

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.

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Leading operator")
c = close
  + open
plot(c)
```

The compiler says: no viable alternative at input '\n+'. Move the operator to the end of the line before.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.