# Inputs

> Turn hard-coded numbers into settings. Every input.* call becomes a field in the indicator's settings, saved per chart.

An input is a value the person using the script can change without touching code. Each `input.*` call adds one field to the indicator's **settings** dialog (the gear in its legend), and the chart re-runs the script with the new value.

```pine
//@version=6
indicator("Envelope", overlay = true)
length = input.int(20, "Length", minval = 1, maxval = 500)
pct = input.float(1.5, "Width %", minval = 0.1, step = 0.1)
src = input.source(close, "Source")
showMid = input.bool(true, "Show basis")
col = input.color(color.new(#8b7cff, 0), "Colour")
basis = ta.sma(src, length)
plot(showMid ? basis : na, "Basis", color = col)
plot(basis * (1 + pct / 100), "Upper", color = col)
plot(basis * (1 - pct / 100), "Lower", color = col)
```

## The input types

| Function | Field in settings |
| --- | --- |
| `input.int` | A whole number, with `minval`, `maxval`, `step` |
| `input.float` | A decimal number, same options |
| `input.bool` | A checkbox |
| `input.color` | A colour picker |
| `input.source` | A choice of series: `close`, `open`, `hl2`, `hlc3`, `ohlc4`… |
| `input.timeframe` | A timeframe picker, for use with `request.security` |
| `input.string` with `options = [...]` | A dropdown |
| `input.text_area` | A multi-line text box |

The second argument is the **title**, which is the label in settings.

## A dropdown

```pine
//@version=6
indicator("Average of your choice", overlay = true)
kind = input.string("EMA", "Average", options = ["SMA", "EMA", "WMA", "HMA"])
len = input.int(30, "Length", minval = 2)
avg = switch kind
    "SMA" => ta.sma(close, len)
    "EMA" => ta.ema(close, len)
    "WMA" => ta.wma(close, len)
    => ta.hma(close, len)
plot(avg, kind, color = color.orange, linewidth = 2)
```

## How saved values behave

Values you set are saved with the indicator on that chart and come back next session. They are matched to inputs by **position in the script**, not by title. So when you later edit the script:

- A number now outside a new `minval`/`maxval` is clamped into range.
- A value whose input changed **type** (say a number that became a checkbox) is dropped, with a warning naming the setting.
- A saved value whose input no longer exists is dropped, with a warning.
- **Inserting** an input above others shifts their positions, so their saved values can land on the wrong field. Add new inputs at the end of the list when a script is already in use.

> [!TIP]
> Give related inputs the same `group = "Bands"` and the settings dialog shows them under one heading, in the order you declared them.
