Why inputs matter
Hard-coded constants work for learning, but real indicators expose their tunables. Inputs become the settings panel any user of your script will see. The right input type gives you the right control — sliders, dropdowns, colour pickers, checkboxes.
Input types
input.int — integers, with optional min/max/step. input.float — same with decimals. input.bool — checkboxes for on/off. input.string — free text or a dropdown. input.source — lets users pick a series (close, high, low, hl2, ohlc4, etc.). input.timeframe — a timeframe picker.
String dropdowns
input.string can take a list of options:
maType = input.string("SMA", "Type", options=["SMA", "EMA", "WMA"])
The settings panel shows a dropdown. You read the selected value as a regular string.
Source inputs
src = input.source(close, "Source") lets the user pick which series feeds your indicator — close, high, hl2, ohlc4, or any other plot on the chart. This single line is what makes a moving-average indicator usable across different chart types and custom feeds.
Tooltips and groups
Inputs accept tooltip and group arguments. tooltip="Period over which the average is calculated" shows a question-mark icon in the settings panel. group="Visuals" clusters related inputs together. Use them once you have more than a handful of inputs.
Defaults and validation
Pick defaults that are sensible for the most common use case. If the user can shoot themselves in the foot (negative length, zero divisor), use minval or guard with if at the top of the script.
A worked example
//@version=5
indicator("Configurable MA", overlay=true)
src = input.source(close, "Source")
length = input.int(20, "Length", minval=1, maxval=500)
maType = input.string("EMA", "Type", options=["SMA", "EMA", "WMA"])
show200 = input.bool(false, "Show 200 reference")
ma = switch maType
"SMA" => ta.sma(src, length)
"EMA" => ta.ema(src, length)
"WMA" => ta.wma(src, length)
plot(ma, color=color.orange, linewidth=2)
plot(show200 ? ta.ema(src, 200) : na, color=color.gray)
What to take from this
Inputs are how you turn a script into a tool. Spend the time to expose the right tunables with sensible defaults and validation — your future self, when you come back to tune the indicator on a live market, will thank you.