input.* Namespace
All input registration functions — int, float, bool, string, source, timeframe, color, enum, and more — with guidance on when to use each.
input.* Namespace#
Every input registration appends metadata into the script context and returns the default value immediately, so your module can use it as a plain Python value.
Method reference#
| Method | Return type | Typical args | Use case |
|---|---|---|---|
input.int(defval=0, title="", key=None, **kwargs) | int | minval, maxval, step | Lengths, lookbacks, counts. |
input.float(defval=0.0, ...) | float | minval, maxval, step | Multipliers, thresholds, sizing. |
input.bool(defval=False, ...) | bool | — | Feature flags and display controls. |
input.string(defval="", ...) | str | Plain text | Modes, source keys, labels. |
input.text_area(defval="", ...) | str | Long-form text | Notes or text payload input. |
input.time(defval=0, ...) | int | Timestamp default | Time anchors. |
input.price(defval=0.0, ...) | float | Price level default | Fixed price references. |
input.source(defval="close", ...) | str | Source field name | Select market source column. |
input.symbol(defval="", ...) | str | Symbol selector | External symbol input. |
input.session(defval="", ...) | str | Session string | Session filtering. |
input.timeframe(defval="", ...) | str | Timeframe string like 15m | MTF confirmation. |
input.color(defval="#00c853", ...) | str | Hex or color string | Visual style input. |
input.enum(defval=None, title="", key=None, options=None, **kwargs) | Any | options | Bounded choice selection. |
Key concepts#
How defval works — defval is the value returned immediately at import time and the value used when the runtime has not supplied an override. Treat it as the script's safe startup configuration.
Why key matters — key is the stable identity for the setting in the runtime. Keep it short, explicit, and durable. Changing keys later breaks continuity between saved settings and the script contract.
How to merge params — Use inputs as typed defaults, then merge params over them inside the frame builder. That keeps the script runnable as plain Python while still respecting runtime overrides.
Choosing the right input family#
| Input family | Choose it when... | Practical guidance |
|---|---|---|
input.int | The value is a discrete count, lookback, or bar distance. | Add minval=1 when zero or negative values would make the indicator invalid. |
input.float | The value is continuous: multipliers, thresholds, percent-like knobs. | Use step to control UI granularity. |
input.bool | The setting toggles a feature on or off. | Good for showing markers, enabling a filter, or switching output layers. |
input.string | The user chooses a small freeform mode label or source name. | For highly constrained choices, prefer input.enum. |
input.source | The user should select a column-like market source. | Always implement a fallback when the chosen source is absent. |
input.timeframe | The user selects an alternate timeframe for confirmation. | Use only when the script actually calls request.security. Do not add as decoration. |
input.price | The setting is a fixed chart level. | Use for thresholds, zones, and manual anchors. |
input.time | The user must choose a specific timestamp. | Useful for fixed-range studies and time-anchored objects. |
input.color | The user controls styling without changing logic. | Keep color inputs cosmetic. Do not overload with semantic decisions. |
input.enum | The choice must be limited to known valid values. | Best for modes like sma vs ema, or named logic variants. |
Input merging pattern#
length = input.int(20, title="Length", key="length", minval=1)
multiplier = input.float(2.0, title="StdDev Mult", key="multiplier", minval=0.1, step=0.1)
source_type = input.source("close", title="Source", key="source_type")
def build_indicator_frame(df, params=None):
frame = df.copy().reset_index(drop=True)
p = {
"length": int(length),
"multiplier": float(multiplier),
"source_type": str(source_type),
} | dict(params or {})
source_name = str(p.get("source_type", "close") or "close")
source_series = frame[source_name] if source_name in frame.columns else frame["close"]
...Mixed input families example#
# input.int for discrete lookbacks
length = input.int(20, title="Length", key="length", minval=1)
# input.float for continuous knobs such as multipliers
multiplier = input.float(2.0, title="StdDev Mult", key="multiplier", minval=0.1, step=0.1)
# input.source when the user chooses a market source column
source_type = input.source("close", title="Source", key="source_type")
# input.timeframe only when the script really does MTF work
confirm_tf = input.timeframe("15m", title="Confirm TF", key="confirm_tf")
# input.color for cosmetic styling, not logic decisions
line_color = input.color("#00c853", title="Line Color", key="line_color")
# input.enum for bounded named choices
ma_mode = input.enum("ema", title="MA Mode", key="ma_mode", options=["sma", "ema", "rma"])