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

# Script anatomy

> The parts of a Lipi v2 script, what may appear only at the top level, and what a script cannot contain.

A script is a list of lines that the chart runs once for every bar (see [Bar-by-bar evaluation](https://gocharting.com/docs/scripting/evaluation/bar-by-bar.md)): a
header, one declaration, then statements and declarations in any order.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Anatomy", overlay=true)
length = input.int(20, "Length", minval=1)
func spread(float a, float b) => a - b
mid = talib.sma(close, length)
if barstate.islast {
    label.new(bar_index, mid, "Spread " + str.tostring(spread(high, low)))
}
plot(mid, title="Average")
```

## The parts

| Part | Rule |
| - | - |
| `//@lipi=2` | A directive that selects the language version, not an ordinary comment. Put it at the top, before any code (see [Statements and lines](https://gocharting.com/docs/scripting/language/statements-and-lines.md)). |
| `indicator(...)` or `strategy(...)` | Exactly one, at the top level, with every argument `const` (see [qualifiers](https://gocharting.com/docs/scripting/language/qualifiers.md)). Put it first. The arguments are in the [reference](https://gocharting.com/docs/scripting/reference/functions/global.md). |
| Statements | Assignments, calls, `if`, `switch`, `for`, `while`. |
| `func`, `def`; `type`, `enum` | Declarations: [functions](https://gocharting.com/docs/scripting/language/custom-functions.md), [types and enums](https://gocharting.com/docs/scripting/language/custom-types.md). |

## Top level only

These may not appear inside a function, `if`, loop or `switch`:

* `indicator`, `strategy`;
* `func`, `def`, `type` and `enum` declarations (a syntax error elsewhere);
* the calls that put output on the chart: `plot`, `plotshape`, `plotchar`, `plotarrow`, `plotbar`, `plotcandle`, `hline`, `fill`,
  `bgcolor`, `barcolor`, `alertcondition`. Inside a block they fail with `` `plot()` must be called in the global scope. `` (the name
  of the call you wrote). To draw only on some bars, put the condition in an argument instead (see [Branching](https://gocharting.com/docs/scripting/language/branching.md)).

Variables, `input.*`, `talib` calls, drawings, `alert` and `strategy.*` orders may be used anywhere.

## What a script cannot contain

* `import`, `export`, `method` and `library()`: there are no libraries or modules.
* `request.*`: a script reads only the symbol and interval of its chart.
* Block comments: only `//` to the end of the line.
* `var` and `varip`: use `static` (see [Values that persist across bars](https://gocharting.com/docs/scripting/evaluation/persistence.md)).

Drawings, arrays, history and run time have fixed limits (see [Limits](https://gocharting.com/docs/scripting/distribution/limits.md)).


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