---
title: Typed Inputs
description: Expose script settings with input(), covering number, select, color, slider, boolean, source, and more.
---

`input()` turns a value into a setting users can change without editing code. Each input you declare shows up in the script's settings panel, and the value you get back drives your logic. This is how you ship a configurable indicator: an adjustable period, a color picker, a source selector, an on/off toggle.

```javascript
//@version=2
define(title="Configurable SMA", position="onchart", axis=true)

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange)

// Surfaces as a "Length" number field in the settings panel.
var length = input(name="Length", type="number", defaultValue=20, label="Length", constraints={min: 2, max: 200, step: 1})

plotLine(value=sma(source=trade.close, period=length), colors=["#2563eb"], width=2, label=["SMA"], desc=["SMA over the user-set length"])
```

Every input takes a `name`, a `type`, a `defaultValue`, and usually a `label` (the text shown in the panel). Numeric and slider types accept `constraints={min, max, step}`. A `group` string buckets related inputs under a heading in the panel.

## Input types

| `type` | Surfaces as | Notes |
| --- | --- | --- |
| `number` | Number field | Accepts `constraints={min, max, step}`. |
| `int` | Number field | Integer only; non-integer default is rejected. |
| `float` | Number field | Decimal value. |
| `boolean` | Toggle / checkbox | Default must be `true` or `false`. |
| `string` | Text field | Free-form text. |
| `select` | Dropdown | Requires `options=[...]`; default must be one of them. |
| `multiSelect` | Multi-pick dropdown | Choose several of the provided `options`. |
| `source` | Source dropdown | Default is a source name like `"ohlcv"`; feed it to `source(...)`. |
| `color` | Color picker | Default is a color (hex or constant). |
| `color[]` | Color list | A list of colors. |
| `slider` | Slider | Numeric; pair with `constraints={min, max, step}`. |
| `timeframe` | Timeframe picker | e.g. `"1h"`, `"1D"`. |
| `session` | Session field | A trading-session string. |
| `symbol` | Symbol picker | A symbol string. |
| `text` | Multi-line text | Longer free-form text. |

{% hint style="warning" %}
The boolean type is spelled **`boolean`**, not `bool`. Using `bool` fails at compile: `input() type must be one of: number, int, float, boolean, string, source, timeframe, session, symbol, color, color[], text, select, multiSelect, slider`.
{% endhint %}

## Examples by type

**Number with min/max/step.** An adjustable period clamped to a sensible range:

```javascript
var length = input(name="Length", type="number", defaultValue=14, label="Length", constraints={min: 2, max: 100, step: 1})
```

**Select with options.** A dropdown that switches behavior:
```javascript
var maType = input(name="MA Type", type="select", defaultValue="ema", label="MA Type", options=["sma", "ema"])
var ma = maType == "ema" ? ema(source=trade.close, period=length) : sma(source=trade.close, period=length)
```

**Color picker.** Let the user recolor the plot:
```javascript
var lineColor = input(name="Line Color", type="color", defaultValue="#2563eb", label="Line Color")
plotLine(value=ma, colorIndex=lineColor, width=2, label=["MA"], desc=["MA in the chosen color"])
```

**Slider.** A bounded value with a draggable handle (here, line width):
```javascript
var width = input(name="Width", type="slider", defaultValue=2, label="Line Width", constraints={min: 1, max: 5, step: 1})
```

**Boolean.** A simple on/off toggle:
```javascript
var showFast = input(name="Show Fast", type="boolean", defaultValue=true, label="Show Fast Line")
```

**Source.** Pick which data feeds the script, then pass the name to `source(...)`:
```javascript
var src = input(name="Source", type="source", defaultValue="ohlcv", label="Source")
timeseries selected = source(type=src, symbol=currentSymbol, exchange=currentExchange)
```
## Organizing the settings panel

The `group` argument places inputs under named headings, so a busy indicator stays readable. Inputs sharing a `group` string are shown together. The example below uses `Periods`, `Bands`, `Display`, and `Source`.

## Every input type in one script

```javascript title="scripts/probes/inputs/all_inputs.ks"
//@version=2
define(title="Verified Inputs", position="offchart", axis=true)

var numberLength = input(name="Number Length", type="number", defaultValue=12, label="Number Length", constraints={min: 2, max: 50, step: 1}, group="Periods")
var intLength = input(name="Int Length", type="int", defaultValue=14, label="Int Length", constraints={min: 2, max: 50, step: 1}, group="Periods")
var floatMultiplier = input(name="Float Multiplier", type="float", defaultValue=1.5, label="Float Multiplier", constraints={min: 0.5, max: 5, step: 0.5}, group="Bands")
var showFast = input(name="Show Fast", type="boolean", defaultValue=true, label="Show Fast", group="Display")
var labelText = input(name="Label Text", type="string", defaultValue="Close", label="Label Text", group="Display")
var averageChoice = input(name="Average", type="select", defaultValue="ema", label="Average", options=["sma", "ema"], group="Periods")
var lineColor = input(name="Line Color", type="color", defaultValue="#2563eb", label="Line Color", group="Display")
var sliderWidth = input(name="Slider Width", type="slider", defaultValue=2, label="Slider Width", constraints={min: 1, max: 5, step: 1}, group="Display")
var sourceName = input(name="Source Type", type="source", defaultValue="ohlcv", label="Source Type", group="Source")

timeseries selected = source(type=sourceName, symbol=currentSymbol, exchange=currentExchange)
var baseAverage = averageChoice == "ema" ? ema(source=selected.close, period=intLength) : sma(source=selected.close, period=numberLength)
var adjusted = baseAverage + (showFast ? floatMultiplier : 0) + (labelText == "Close" ? 0 : 1)

plotLine(value=adjusted, colorIndex=lineColor, width=sliderWidth, label=["Input result"], desc=["input driven moving average"])
```


## Defaults are type-checked

The `defaultValue` must match the declared `type`, and the engine checks it at compile time. This catches typos before the script runs:

| Mistake | Error |
| --- | --- |
| String default for a `boolean` | `defaultValue for type 'boolean' must be true or false` |
| String default for a `number` | `defaultValue for type 'number' must be a number` |
| Decimal default for an `int` | `defaultValue for type 'int' must be an integer` |
| String default for a `float` | `defaultValue for type 'float' must be a number` |
| Number default for a `string` | `defaultValue for type 'string' must be a string` |
| `select` default not in `options` | `defaultValue '...' for type 'select' must be one of the provided options` |
| Number default for a `color` | `defaultValue for type 'color' must be a color` |
| String default for a `slider` | `defaultValue for type 'slider' must be a number` |
| Number default for a `source` | `defaultValue for type 'source' must be a string` |

If you see one of these, line up the `defaultValue` with the `type` (and for `select`, make sure the default is one of the listed `options`).
