Skip to content

Inputs ​

How do you let a user set your script's lengths, sources and colours without editing its text? Read each setting through an input.* call. The call returns its default until the user changes the value in the study's Settings, and then the script runs again with the new one.

pine
//@version=6
indicator("Moving average", overlay = true)
int    len  = input.int(20, "Length", minval = 1, group = "Average")
float  src  = input.source(close, "Source", group = "Average")
string kind = input.string("SMA", "Kind", options = ["SMA", "EMA"],
     group = "Average")
color  col  = input.color(color.orange, "Line", group = "Style")
float sma = ta.sma(src, len)
float ema = ta.ema(src, len)
// a saved setting finds its input by title: keep titles unique
plot(kind == "SMA" ? sma : ema, "MA", col)

An input's value is fixed for the whole run. It can't change from bar to bar, so you can use it where Pine wants a value known before the first bar, such as a length.

The kinds ​

Each kind gives the Settings panel its own control.

CallGivesSettings shows
input.int(14, "Length")intA number field. With options, a list
input.float(2.0, "Mult")floatA number field. With options, a list
input.bool(true, "Show")boolA check box
input.string("Fast", "Mode", options = [...])stringA text field. With options, a list
input.text_area("...", "Notes")stringA box of several lines
input.color(color.red, "Colour")colorA colour picker
input.source(close, "Source")series floatA list of the bar's prices, and other studies' plots
input.symbol("AAPL", "Symbol")stringA symbol search
input.timeframe("1D", "Timeframe")stringA timeframe list
input.session("0930-1600", "Session")stringSession hours
input.time(timestamp("2024-01-01"), "Start")int, in UNIX msA date and time, and a handle you drag on the chart
input.price(100.0, "Level")floatA price, and a handle you drag on the chart
input.enum(Side.long, "Side")The enumA list of the enum's titles
input(20, "Length")The default's typeWhat that type gets

The source list holds open, high, low, close, hl2, hlc3, hlcc4, ohlc4 and volume, in that order. It also holds the plots of the other studies on the chart, so one study can read another's output bar by bar. A plain input() takes its kind from its default, and a default of a price such as close makes it a source input.

Laying out the Settings panel ​

The arguments after the title shape the panel:

ArgumentDoes
groupPuts the input under a heading of that name. Inputs with no group sit under Inputs
inlinePuts the inputs of one group that share this name on one row
tooltipShows this text beside the input
optionsTurns the field into a list of these values
minval, maxval, stepBound and step a number field. A typed value out of range is refused, with a note saying the range
displayWhether the value shows after the study's name on the chart. By default every kind shows but bool, color and input.time. display.none hides it
confirmAsks for the value when the study is added (below)

TradingView's active argument, which greys an input out, is accepted and does nothing here.

How a saved setting finds its input ​

A value set from outside the script is an override. The Settings panel writes one, and so do saved presets and each try of an Optimizer sweep. Each override names its input by a key, and the engine tries three keys in turn:

  1. The input's id, which only AmenoScript has (input.int(20, "Length", id = "len")). See AmenoScript inputs.
  2. Its title. A title belongs to the first input that uses it, so a second input with the same title is never reached by it.
  3. in_N, its place among the script's input calls, counting from 0. An input with no title shows in the panel as Input in_N, with N its number, as in Input in_2.

So give every input its own title. A title is a key that survives moving the input up or down the script, where in_N changes whenever you add or remove an input above it.

When you edit a script that's already on a chart, the study keeps each saved value it can still match to an input. It matches by id, then by title. An input with no title, or whose title an input above it took first, is matched by its position, and only while no input above it was added or removed. A value it can't match is dropped, and the study's legend shows how many were dropped until you next change a value.

Asking for a point when the study is added ​

confirm = true asks the user for the value as the study goes on the chart. A time or a price input with it asks for a click on the chart, and a toast at the chart's foot names what it wants. A time input and a price input on the same inline row make one point, set by one click.

pine
//@version=6
indicator("Level from a click", overlay = true)
// a time and a price on one inline row: one click sets both
int   anchor = input.time(timestamp("2024-01-01"), "Anchor",
     confirm = true, inline = "point")
float level  = input.price(0.0, "Price", confirm = true, inline = "point")
plot(time >= anchor ? level : na, "Level", color.orange,
     style = plot.style_linebr)

After the clicks, the Confirm Inputs panel lists every input marked confirm, of any kind. Cancel or the panel's close button takes the study off the chart, and so does Esc while the chart is still asking for clicks. While it waits, the study has already run on its defaults, so its plots are hidden until you finish. A study that's selected shows a handle for each time and price input, which you can drag, and its menu's Reset points asks for every point again.

The chart asks only when a study is added fresh, from the picker, from the editor, or pasted as a bare title. A saved layout, a pasted line with values and a copy made on the chart don't ask.

Traps ​

  • A default must be a constant. Our engine runs input.int(bar_index > 5 ? 10 : 20) with a qualifier: warning, but TradingView refuses to compile it.
  • An enum input's saved value is the option's title, such as "Long only", not the field's name.
  • minval and maxval bound what the Settings field takes. A value from a preset or a run reaches the script as it is, so test it yourself if a bad one would break the script.
  • Renaming an input's title loses the values saved under the old one, unless the input has an AmenoScript id.
  • Two inputs with the same title share one key, and only the first is reached by it.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.