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

# Moving a script from Lipi v1 to v2

> The version header, what Lipi v2 adds to Lipi v1, and what to check when you move a v1 script.

A Lipi v1 script is a script without the `//@lipi=2` line. To move one, add the line as the first line and check the script again.
Almost every v1 script keeps compiling; this page lists what Lipi v2 adds and the few things that change.
Lipi v2 runs in Terminal V2. The Classic Terminal runs scripts written for Lipi v1.

## Step 1: the header

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

The editor reads the first `//@lipi=N` it finds. With `N` equal to 2 the script is checked as Lipi v2. With no line, or with
`//@lipi=1`, it is checked as Lipi v1, which is why a v2 script pasted without its header fails with errors such as
``No variable with name `array` found.`` A number above 2 is refused: `unsupported //@lipi=3 at line 1, column 1: lipi should be <= 2`.

## What Lipi v2 adds

Each of these is refused by the v1 check and accepted in v2.

| Addition | What the v1 check says |
| - | - |
| Arrays: `array.new<float>(0)`, `array<float>`, `for x in a` | ``No variable with name `array` found.``; `` `array<float>` is not a valid type in variable declaration. ``; `Not Implemented` for `for x in a` |
| Drawings: `label`, `line`, `box`, `linefill`, `polyline`, and tables | ``No variable with name `label` found.`` (likewise `line`, `box`, `table`) |
| Strategies: `strategy(...)` and the `strategy.*` calls | ``Could not find function or function reference `strategy`.`` |
| Compound assignment: `+=`, `-=`, `*=`, `/=`, `%=` | `Not Implemented` |
| `barstate.isconfirmed` | ``No variable with name `barstate` found.`` |
| `color.from_gradient` | ``Could not find any function `from_gradient` in namespace `color`.`` |
| `input.enum` | ``Could not find any function `enum` in namespace `input`.`` |
| `indicator()` arguments `calc_on_every_tick`, `max_lines_count` and the other `max_*_count`, `scale`, `calc_bars_count`, `behind_chart` | ``Unknown named argument `calc_on_every_tick`.`` |
| The `display` argument and the `display.*` constants | ``No variable with name `display` found.`` |
| `time(...)` and `time_close(...)` as functions, `last_bar_index`, `last_bar_time`, `time_sessionday`, `interval.change`, `interval.in_seconds`, `interval.from_seconds`, `interval.isseconds`, `dayofweek.monday` and the other days, `math.round_to_mintick`, `str.split` | the name is not found |
| The namespaces `chart`, `format`, `position`, `order`, `text`, `extend`, `xloc`, `yloc` | ``No variable with name `chart` found.`` and similar |

The v1 check already accepts these, so a v1 script that uses them needs no change: `type` and `enum` declarations with
`Name.new(...)` and field assignment, `switch`, `for`, `while`, `break` and `continue`, `static` and `intra`, functions written with
`func` or no keyword, `def` methods, tuple returns, `alert` and `alertcondition`, `talib.*` and `ta.*`, and every `input.*` function except
`input.enum`. The check compares what the compiler accepts, not what the script draws; test a moved script on a chart.

Compound assignment is the change you will use most. A v1 script, as it stands:

```text theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
indicator("Up bars so far")
static int ups = 0
if close > open {
    ups := ups + 1
}
plot(ups, title="Up bars")
```

The same script in v2: the header is added, and the counter can use `+=`.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Up bars so far")
static int ups = 0
if close > open {
    ups += 1
}
plot(ups, title="Up bars")
```

## What to check when you move a v1 script

1. **`math.sum(a, b, c)` adds its arguments in v1. In v2 it is a moving sum, `math.sum(source, length)`.** A v1 call with three
   arguments is refused: ``Too many arguments passed into the `math.sum()` function call. Passed 3 arguments but expected 2.`` A call
   whose second argument is a whole number compiles in both versions and means something else. Write `a + b + c` for the v1 meaning; `math.sum(close, 10)` is the sum of
   the last 10 closes.
2. **Variable names that match a namespace now warn.** Lipi v2 has many more namespaces, so a v1 variable called `line`, `label`,
   `box`, `table`, `array`, `strategy`, `position`, `order`, `text`, `format`, `chart` or `interval` compiles with the warning
   ``Variable `line` hides the built-in namespace `line`.`` Rename it.
3. **`plotbar` takes `display` before `force_overlay`.** A v1 call that passes `force_overlay` as the seventh argument is refused
   (``Cannot call `plotbar` with argument `display`=`true`. ...``); pass it by name.
4. **A negative history index is now refused by the check.** `close[-1]` passes the v1 check; v2 stops it:
   `History index must be >= 0. Got -1.`
5. **Run the Add to chart rules.** Lipi v2 applies further rules when the script is added to the chart (see
   [The Lipi editor](https://gocharting.com/docs/scripting/getting-started/editor.md)). A clean editor check is not enough.
6. **Functions have more arguments, all at the end.** `plot`, `hline`, `fill`, `barcolor`, `bgcolor`, the `plotshape` family and the
   `input.*` functions gained `display` and, for some, `format`. Scripts that pass their arguments by name or in the v1 order are
   unaffected (apart from `plotbar`, above).

`var`, `varip`, `^` and `;` are refused in both versions. See [What Lipi does not do](https://gocharting.com/docs/scripting/getting-started/not-supported.md).


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