Inputs
The settings the user changes in the dialog, written as arguments of the function.

from totaltrade.v1 import indicator, request, input, plot, color, ta
@indicator(short="Session", overlay=True, plots=[
plot.series("average", "Average", color=color("#2962FF"), width=2),
plot.background("session", "Session", color=color("#2962FF", 10)),
])
def calculate(
bars=request.bars(),
length=input.int("Length", 20, min=1, group="Average"),
kind=input.choice("Type", "ema", options=[
("sma", "Simple"),
("ema", "Exponential"),
], group="Average"),
start=input.time("Start", "09:30:00", group="Session", inline="session",
tooltip="In the symbol time zone"),
end=input.time("End", "16:00:00", group="Session", inline="session"),
show=input.bool("Color the session", True, group="Session"),
):
average = ta.ma(bars.close, length, kind)
inside = bars.calendar.between(start, end)
return {"average": average, "session": [show and x for x in inside]}Types
| Input | In the settings | The function receives |
|---|---|---|
input.int(label, default) | A whole number | int |
input.float(label, default) | A decimal number | float |
input.bool(label, default) | A toggle | bool |
input.choice(label, default, options) | A dropdown | The chosen value, a text or None |
input.time(label, default) | A time, with hours, minutes and seconds | "hh:mm:ss" |
input.color(label, default) | A color with opacity | A color |
input.line(label, default) | The drawings’ line | The line= dictionary |
input.fill(label, default) | The drawings’ fill | The fill= dictionary |
input.font(label, default) | The drawings’ font | The "style" dictionary in text= |
input.intandinput.floatalso havemin,maxand thestep.- The options of
input.choiceare(value, label)pairs: the user sees the label, the function receives the value. - A time is always written with seconds,
"09:30:00": this way times can also be compared as text.
In the legend
Next to the indicator’s name the legend shows the values of the numeric inputs and of the choices, the choices with their label: for example “Session 20 Exponential”. Toggles, times, colors and styles don’t appear: they are settings, not calculation parameters, and ten session times would fill the row.
When you change the script
When you save the script, its copies on the charts keep the values chosen by the user. If you remove an option from an input.choice, anyone who had chosen it goes back to the default value, both in the calculation and in the settings. A new input starts from its default.
Sections, rows and help
All inputs accept four arguments to decide where they sit and when they apply:
group: the title of the section it appears in.inline: any name; inputs with the sameinlinesit on the same row, like Start and End above.tooltip: a help text, shown when you hover over the icon next to the label.active: aninput.bool. When it’s off the field stays visible but dimmed, and can’t be changed. The function still receives its value.
show_ma = input.bool("Show the average", True)
length = input.int("Length", 20, min=1, active=show_ma)
# in the function arguments: show=show_ma, n=lengthInputs appear in the order you write them; a section or a row sits where the first input that uses it appears. In a row, an input.bool written last shows only the toggle, and the label of the field before applies to both.
Drawing styles
input.line, input.fill and input.font are the drawing styles, each in a single setting, with the same popover as a drawing’s settings. The default is written like the drawing’s argument; whatever is missing comes from the drawings. The function receives the same dictionary, to pass on as it is.
line=input.line("Line", {"color": color("#FFFF00"), "width": 2}),
fill=input.fill("Zone", {"color": color("#2962FF", 15), "gradient": True}),
font=input.font("Text", {"color": color("#FFFFFF"), "size": 12}),
# in the function:
draw.trend_line((i, price), (i + 1, price), line=line)
draw.rectangle((start, high), (end, low), fill=fill, text={"value": "Zone", "style": font})The colors of these inputs are hexadecimal, like those of the drawings: a theme color like color("up") is an error.
An input for the timeframe
An input.choice passed to request.bars lets the user choose the timeframe. Each option must be a valid timeframe, or None for the chart’s. To pick it from the chart’s timeframe, without an input, see From the chart’s timeframe.
htf=request.bars(timeframe=input.choice("Timeframe", "W", options=[
(None, "Chart"),
("D", "Day"),
("W", "Week"),
])),Here the input’s key is htf: written inside another declaration, it takes that one’s name. In the same way an input.choice passed to request.events chooses the news currencies or impacts: see News.