Guides
Settings
Each input.* call creates a setting in the Settings tab of the StrateScript panel and returns its current value. Settings turn fixed numbers into choices the user can change without touching the code.
Rules#
- The first argument is the setting's title, a text (E925 otherwise). The title is the setting's identity: the value the user chose is stored under it. Renaming the title in the code brings the default back.
- Two calls with the same title return the value of the first one.
- Settings belong to each chart the script is on.
- In an imported script, settings appear as
alias · Title. An import line can override them ({ len: 50 }), which removes them from the Settings tab. See Imports. - Only
input.intandinput.floatsettings can be swept in a strategy report (see Strategies).
Functions#
| Function | Returns | Options and errors |
|---|---|---|
input.int(title, default, min:, max:, step:) | A whole number (the default and the user's value are rounded), kept within min and max. | step: is the step of the input control (default 1). |
input.float(title, default, min:, max:, step:) | A number kept within min and max. | |
input.bool(title, default) | A bool (a checkbox). | |
input.color(title, #rrggbb[aa]) | A color. | |
input.duration(title, 30s) | A duration. | |
input.string(title, "text") | A text. | |
input.choice(title, ["A", "B"], default?) | One of the texts in the list; without a default, the first option. | A second argument that is not a list gives E925. |
input.session(title, "HHMM-HHMM[,…][:days]") | A time-range text for session.in. An invalid value typed by the user falls back to the default. | An invalid default gives E925. |
input.price(title, 0) | A price picked by clicking on the chart. Returns na until a price is picked (0 or na means "not picked"). | A default that is not a number gives E925. |
input.time(title, 0) | An instant picked by clicking on the chart, snapped to the open of the bar. Returns na until picked. | A default that is not a time gives E925. |
Layout options (all functions):
group: "Name"puts the setting in a collapsible group;inline: "id"puts consecutive settings of the same group with the same id on one line;tooltip: "text"adds an information icon with that text.
indicator "Inputs demo" { overlay: true }
len = input.int("Length", 20, min: 1, max: 500, group: "Calculation", tooltip: "Bars in the average")
mult = input.float("Width", 2.0, step: 0.1, group: "Calculation")
src = input.choice("Source", ["close", "hl2"], "close", group: "Calculation")
up = input.color("Up", #26a69a, group: "Colors", inline: "c")
dn = input.color("Down", #ef5350, group: "Colors", inline: "c")
hours = input.session("Hours", "0930-1600:12345")
lvl = input.price("Level", 0)
x = src == "close" ? close : (high + low) / 2
basis = sma(x, len)
dev = stats.stdev(x, len) * mult
plot(basis + dev, up, title: "Upper")
plot(basis - dev, dn, title: "Lower")
bg_color(session.in(hours) ? #ffffff08 : na)
if not na(lvl) { hline(lvl, color: #e8c15a, text: "Level") }Distances in ticks or points#
A setting cannot be followed by a unit word: n ticks with a variable n is a syntax error (E106), because units only follow a number literal. Convert explicitly:
| You want | Write |
|---|---|
| A distance set in ticks | d = price(input.int("Stop (ticks)", 8)) — price(n) is n × instrument.tick |
| A distance set in points | d = input.float("Stop (points)", 2.0) — a plain number is already a price distance |
| A price distance shown in ticks | ticks(high - low) |
indicator "Bands in ticks" { overlay: true }
offset = input.int("Offset (ticks)", 8, min: 1)
d = price(offset)
plot(close + d, #26a69a80, title: "Up")
plot(close - d, #ef535080, title: "Down")Thresholds that adapt: normalized settings#
A setting that holds a raw threshold ("volume ≥ 500") must be retuned for each instrument and each period. A setting that holds a rank ("volume rank ≥ 95") does not. Let the user choose the unit:
indicator "Heavy volume" { overlay: true }
unit = input.choice("Volume in", ["rank", "zscore", "x_median", "raw"], "rank", group: "Threshold")
minVol = input.float("Min volume", 95, group: "Threshold", tooltip: "In the unit chosen above")
win = input.duration("Normalize over", 4h, group: "Threshold")
v = norm.unit(volume, unit, win)
marker(v >= minVol and bar.confirmed, shape: "circle", location: "above", color: #e8c15a)See Normalization.
Picking a price or a time on the chart#
input.price and input.time let the user point at the chart instead of typing a number. Until a value is picked they return na, so test for it:
indicator "Distance to my level" { overlay: false }
lvl = input.price("My level", 0)
since = input.time("Since", 0)
plot(na(lvl) ? na : (close - lvl) / instrument.tick, #2962ff, title: "Distance (ticks)")
bg_color(not na(since) and bar.time >= since ? #2962ff10 : na)
hline(0)