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

# The Lipi editor

> How the editor checks a script, what a problem report contains, and what a clean check does not prove.

You write scripts in the Lipi editor and check them there. A check parses the script, resolves every name and checks every type
without running it against any bars. A clean check means the script is well formed; it does not mean it will run or that it will be
accepted on the chart. This page lists what each phase checks. The check reads the first `//@lipi=N` line: `N` equal to 2 checks the script as Lipi v2, and with no line, or `//@lipi=1`, it is checked as Lipi v1 (see [Moving a script from Lipi v1 to v2](https://gocharting.com/docs/scripting/getting-started/migrating-from-v1.md)).

## Three phases

| Phase | When | What it applies |
| - | - | - |
| The editor's check | You check the script in the editor | Grammar, names, types, qualifiers, argument rules, scope rules |
| Adding the script to the chart | You press Add to chart | Everything above, plus a few further rules (listed below) |
| Running the script | Bar by bar, on the chart | Limits that depend on the data, such as an array index |

## What a check reports

Each problem has a start and an end position (line and column) and a message, and comes in one of two groups.

* **Errors** stop the script. A script with several syntax errors shows only the last one found, and a name or type error usually stops
  at the first one, so fix what is reported and check again.
* **Warnings** do not stop the script. Examples: `Unreachable code detected.`, `opacity 50 is outside 0–1; 1 is solid`, ``Do not use the `na` variable to compare other values to 'na', use the `na()` function instead``, and
  ``Variable `line` hides the built-in namespace `line`.``

A clean check also returns what the script resolved to: its variables with their types, its functions with their signatures, its
types and enums, and its scopes. For this script

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Symbols")
func half(float a) => a / 2
type P {
    float v
}
enum E {
    A
}
float h = half(close)
b = h == 5
plot(h)
```

the check lists the variables `h` (`series float`) and `b` (`series bool`), the function `half(series float a) → series float`, the type
`P` with its field `v`, and the enum `E` with its member `A`. Use it to see what an unfamiliar script declares.

## What a clean check does not prove

### Rules that apply only when the script is added to the chart

These pass the editor's check and fail on Add to chart:

| Written | The compiler says |
| - | - |
| `indicator("x", format=format.mintick)` (or `strategy(...)`) | The `format` argument of `indicator()` only accepts format.inherit, format.price, format.volume, or format.percent. Got `format.mintick`. |
| `indicator("x", calc_bars_count=-1)` | The `calc_bars_count` argument of `indicator()` must be 0 or a positive integer. |
| an `indicator()` title or short title over 128 characters | String is too long (130 characters). Maximum length is 128. |
| `display=display.pane` (or any value but `display.all` and `display.none`) on `barcolor`, `bgcolor` or `fill` | `barcolor()` display argument only supports display.none and display.all. (the same text for `bgcolor()` and `fill()`) |
| `format=format.inherit` or `format.mintick` on `plot` or `hline` | The `format` argument only accepts format.price, format.percent, or format.volume. Got `format.inherit`. |
| an `input.*` argument that is `na` through a variable, or `input.time(timestamp("2024-01-01"))` | Argument `defval` of `input.float()` cannot be `na`. |
| a length above 500 in some `talib` functions, for example `talib.ema(close, 501)` | The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500. |
| a `switch` statement inside a function of yours that the script calls | Not Implemented |

A literal `na` for an input argument is refused by the editor's check itself.

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

The compiler says, on Add to chart: The `format` argument of `indicator()` only accepts format.inherit, format.price, format.volume, or format.percent. Got `format.mintick`.

### Errors that happen while the script runs

The check never executes the script, so it cannot see these:

* A history index above 500: `close[501]` passes both checks and stops the script with "The script is trying to access historical data
  outside allowed range (501). The allowed range is 0 to 500."
* An array index outside the array: `array.get(a, 0)` on an empty array stops the script (see [Arrays](https://gocharting.com/docs/scripting/language/arrays.md)).
* A `for` loop whose `step` points the wrong way, a drawing text over 999 characters, an array over 10,000 elements.
* A script that runs longer than 45 seconds on the chart's history is cancelled.
* A strategy direction that is not `strategy.long` or `strategy.short`, such as `strategy.entry("L", "buy")`.
* Orders and results: a clean check of a strategy runs no bars, so it shows no orders, trades or equity. Add the script to the chart to see them.

Read [Limits](https://gocharting.com/docs/scripting/distribution/limits.md) for the numbers, and test a script on a chart before you rely on it.


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