ScriptingConfigurationInputs

Inputs

An input is a setting the reader of your script can change from the chart, without editing your code. You call an input function once. The platform draws a control for it, and the call gives you back the value the reader chose.

The input functions live in the input namespace.

The eleven kinds of input

There are eleven input functions, one for each kind of control.

FunctionAsks the reader forGives you back
input.boola true or false valueinput bool
input.colora colourinput color
input.floata decimal number, with optional bounds and a stepinput float
input.inta whole number, with optional bounds and a stepinput int
input.pricea priceinput float
input.sessiona sessioninput string
input.sourcea series from the chartseries float
input.stringa line of textinput string
input.text_areaa longer piece of textinput string
input.timea timeinput int
input.timeframea timeframeinput string

Alongside the eleven, input itself accepts six kinds of default value and returns a value of the matching kind.

Your first input

indicator("Source input")
src = input.source(close, "Source")
plot(src)

The first argument is the value the control starts at. The second is its label. The call returns the reader’s choice, so the plotted series follows the control.

the Options tab the platform adds to the Settings dialog

input

input(const bool defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input bool
input(const color defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input color
input(const float defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input float
input(const int defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input int
input(const string defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input string
input(series float defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → series float

input picks its kind from the type of the default value you hand it. Give it a boolean and you get a boolean back. Give it a colour and you get a colour. The last form takes a series and returns a series, which is how you offer a choice of chart data without naming the function for it.

input has no bounds and no step. For a number that needs a minimum, a maximum or a step, use input.int or input.float.

the control drawn for a generic input

Whole numbers and decimals

input.int(const int defval, const string title, const int minval, const int maxval, const int step, const string tooltip, const string inline, const string group, const bool confirm) → input int
input.float(const float defval, const string title, const float minval, const float maxval, const float step, const string tooltip, const string inline, const string group, const bool confirm) → input float

These two take three numeric arguments that no other input function has: minval, maxval and step.

ParameterTypeRequiredWhat it is
defvalconst intyesthe value the control starts at
titleconst stringnothe label
minvalconst intnothe lowest value accepted
maxvalconst intnothe highest value accepted
stepconst intnothe size of one increment
tooltipconst stringnohelp text for the control
inlineconst stringnokey that puts controls on one row
groupconst stringnoheading the control sits under
confirmconst boolnoask the reader to confirm the value

The table is input.int. input.float is the same, with const float in place of const int for the value and for the three numeric arguments.

Passing step

step can only be passed positionally. Naming it is a parse error, because step is a word the grammar reserves for counted loops.

This does not parse:

length = input.int(14, "Length", step = 5)

Pass the arguments before it positionally instead, so that step lands in its own place:

length = input.int(14, "Length", 1, 200, 5)

If you want a step but no bounds, pass na for the bounds:

length = input.int(14, "Length", na, na, 5)

Everything after step can be passed positionally too, so a tooltip still fits:

length = input.int(14, "Length", 1, 200, 5, "Bars in the calculation")

Read this section twice before you publish. This mistake is the commonest cause of a compile failure.

the control drawn for an integer input

Choosing a series

input.source(series float defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → series float

input.source returns a series float rather than an input-form value, so what you get back can differ on every bar. The series form of input behaves the same way. Every other input function returns an input-form value.

True or false, and colours

input.bool(const bool defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input bool
input.color(const color defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input color
show = input.bool(true, "Show the level")

the colour picker drawn for a colour input

Text, prices, times and timeframes

input.string(const string defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input string
input.text_area(const string defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input string
input.session(const string defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input string
input.timeframe(const string defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input string
input.time(const int defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input int
input.price(const float defval, const string title, const string tooltip, const string inline, const string group, const bool confirm) → input float

These six take the same arguments as input.bool: a default value, a title, and the four presentation arguments below. None of them has bounds or a step.

What an input gives you back

A value that came from an input carries the input form. You never write that qualifier yourself. The call produces it.

In the ordering of forms, input sits between const and simple, so an input value can be used wherever a simple or a series value is wanted. The two exceptions above still hold: input.source and the series form of input hand you a series float.

na in an input argument

An input argument cannot be na. The interpreter rejects it. The exceptions are minval, maxval and step, which may be na to mean unbounded or unstepped.

Tooltip, group, inline and confirm

Beyond the value and its title, every input takes the same four presentation arguments: a tooltip, a group to sit under, an inline key that puts several controls on one row, and a confirmation flag.

All four are optional, and all four are const, so none of them can be built from series data.

A worked example

indicator("Input gallery")
src = input.source(close, "Source", "The series this indicator reads")
level = input.float(100.0, "Level", 0.0, 100000.0, 0.5, "A fixed price to draw a line at")
plot(src)
plot(level)

The source input chooses which series is drawn. The level input is bounded and stepped, so its three numeric arguments and its tooltip are all passed positionally.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade