Inputs and Settings
Declaring configurable inputs, grouping them, and how defaults travel with a saved chart.
Every control in the settings panel comes from an input call in the script. The available constructors are input.int, input.float, input.bool, input.string, input.enum, input.color, input.source, input.timeframe, input.time and input.symbol. Each returns the current value, so the declaration and the use are the same line.
Numeric inputs accept minval, maxval and step. Set them. They prevent a length of zero from producing na for the rest of the session, they make the slider behave, and they document the range over which the script was actually designed to work. input.enum takes an options list and renders a dropdown, which is a far better fit than a free-text string for a method selector.
group.settings opens a titled section, and every input declared after it lands in that group until the next call. Two or three groups — calculation, display, alerts — is usually enough. Order inputs the way a user would tune them, with the ones that change behaviour above the ones that change colour.
input.source lets the user choose which series feeds the calculation, defaulting to close but accepting any plotted series from another indicator on the same chart. That is how a smoothing script can be pointed at someone else output without either script knowing about the other. input.timeframe pairs with data.request for higher timeframe anchors.
Settings travel with the chart, not with the script. Changing a value in the panel saves an override on that chart layout; the defaults in the file are what a fresh instance gets. Reset to defaults clears the overrides, and a template captures the overrides so a tuned configuration can be reapplied to another symbol in one click.
Example
AlgoBeamScript — inputs and settings
//@version=2
indicator("Volatility Bands", overlay = true, pane = "main")
group.settings("Calculation")
len = input.int(20, "Length", minval = 2, maxval = 500, step = 1)
mult = input.float(2.0, "Band width", minval = 0.25, step = 0.25)
src = input.source(hlc3, "Source")
method = input.enum("EMA", "Average", options = ["SMA", "EMA", "WMA", "RMA"])
group.settings("Display")
showFill = input.bool(true, "Shade the channel")
bandColor = input.color(color.accent, "Band color")
offset = input.int(0, "Offset", minval = -50, maxval = 50)
higherTf = input.timeframe("1D", "Anchor timeframe")
basis = method == "SMA" ? ta.sma(src, len)
: method == "EMA" ? ta.ema(src, len)
: method == "WMA" ? ta.wma(src, len)
: ta.rma(src, len)
dev = mult * ta.stdev(src, len)
daily = data.request(higherTf, ta.atr(14))
// offset shifts the drawn line along the time axis and changes no value:
// positive draws it forward, negative back.
plot(basis + dev, title = "Upper", color = bandColor, offset = offset)
plot(basis - dev, title = "Lower", color = bandColor, offset = offset)
plot(basis, title = "Basis", color = color.fg_subtle, style = plot.dashed,
offset = offset)
fill(basis + dev, basis - dev, color = color.fade(bandColor, 92), when = showFill)
label.value("Daily ATR", daily, corner = corner.top_right)Copy it, change one input, and run it again — the numbers are deterministic, so a difference in the output is always a difference you made.