# How a script is laid out

> Header, inputs, calculations, rules, drawing.

Source: https://algobarsx.com/docs/script-layout/

A script reads from top to bottom in five parts. Only the header is required.

```algobarsx
algobarsx 1
# 1. Header: what kind of script this is, and its settings
strategy "Layout"
    market: EURUSD
    bars: 15m

# 2. Inputs: what the person running it may change
input length = 20

# 3. Calculations: worked out on every bar
trend_up = close > ema(close, length)

# 4. Rules: when something is true, do something
when starts(trend_up):
    buy risk: 1%, stop: 20 pips, target: 2R

# 5. Drawing: what the chart shows
plot ema(close, length), color: blue
```

- **Blocks are indented with spaces.** A line ending in a colon opens a block, and the lines under it are indented. Tabs are an error ([AS0003](https://algobarsx.com/docs/diag-text-and-layout/#AS0003)).
- **Comments** start with `#` and run to the end of the line.
- The optional first line `algobarsx 1` names the language version the script was written for.
- Line breaks inside `( )`, `[ ]` or `{ }` are ignored, so long expressions can span lines there.
- Names are case-sensitive. A short list of words is reserved, such as `when`, `on`, `if`, `state` and `input`. The full list is in the [grammar](https://algobarsx.com/docs/grammar/).

At each bar close the runtime works in a fixed order: fills and management inside the bar, then `on fill` and `on exit`, then calculations, then confirmations and sequences, then rules in script order, then exports and drawing. Orders your rules create take effect from the next bar. See [E21](https://algobarsx.com/docs/rules-strategy-controls/#E21) and [E1](https://algobarsx.com/docs/rules-timing/#E1).
