Appearance
Input Parameters
Kind: module
Namespace: input
Provides functions for declaring configurable input parameters. Parameters are declared in the init section, and their default values can be changed by the user without modifying the source code.
Caveats
- Must be called in the
initsection, not insideonTick()function. - Must be at the top level, not inside conditionals or loops. This ensures all parameters are discoverable.
Pitfall
javascript
const mode = input.string("mode", "fast");
if (mode === "fast") {
const mult = input.double("mult", 2.0); // ❌ inside conditional
}
function onTick() {
const len = input.double("len", 20); // ❌ inside onTick()
}input()
Kind: func
Adds an input with automatic type detection based on the default value.
Syntax
input(name, defValue) → bool | double | string | color | sourceArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | any | Default value. Type determines input kind (see Notes) |
Returns
The value of the input with the same type as defValue.
Notes
Type is inferred from defValue:
| Default value type | Input kind | Description |
|---|---|---|
bool | bool | Checkbox |
number | double | Numeric field |
string | string | Text field |
color | color | Color picker |
| built-in series | source | Source selector |
Example
javascript
const length = input("length", 20); // double
const useEma = input("useEma", true); // bool
const title = input("title", "Average"); // string
const lineColor = input("lineColor", color.RED); // color
const source = input("source", close); // source
function onTick() {
const avg = useEma ? ta.ema(source, length) : ta.sma(source, length);
spline(avg, {title: title, color: lineColor});
}input.bool()
Kind: func
Adds a bool input (checkbox).
Syntax
input.bool(name, defValue) → boolArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | bool | Default value (true or false) |
Returns
The bool value of the input.
Example
javascript
const useEma = input.bool("useEma", true);
function onTick() {
const avg = useEma ? ta.ema(close, 20) : ta.sma(close, 20);
spline(avg, {title: "Average"});
}input.double()
Kind: func
Adds a double input.
Syntax
input.double(name, defValue) → double
input.double(name, defValue, {min, max, step}) → double
input.double(name, defValue, {options}) → doubleArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | double | Default value |
Options
With constraints:
| Name | Type | Description |
|---|---|---|
| min? | double | Minimum allowed value |
| max? | double | Maximum allowed value |
| step? | double | Step increment for UI |
With predefined values:
| Name | Type | Description |
|---|---|---|
| options? | double[] | List of allowed values |
Returns
The double value of the input.
Notes
stepis used for UI control only and does not affect validation- Use either
{min, max, step}or{options}. If both specified,optionstakes precedence
Example
javascript
// Basic
const length = input.double("length", 20);
// With min/max constraints
const period = input.double("period", 14, {
min: 1,
max: 500
});
// With min/max constraints and step
const multiplier = input.double("multiplier", 2.0, {
min: 0.1,
max: 10.0,
step: 0.1
});
// With predefined options
const deviation = input.double("deviation", 2.0, {
options: [1.0, 1.5, 2.0, 2.5, 3.0]
});input.string()
Kind: func
Adds a text input or dropdown selector.
Syntax
input.string(name, defValue) → string
input.string(name, defValue, {options}) → stringArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | string | Default value |
Options
| Name | Type | Description |
|---|---|---|
| options? | string[] | List of allowed values |
Returns
The string value of the input.
Example
javascript
// Free text
const title = input.string("title", "My Indicator");
// Dropdown selector
const avgType = input.string("avgType", "SMA", {options: ["SMA", "EMA", "WMA"]});
function onTick() {
let avg;
switch (avgType) {
case "SMA":
avg = ta.sma(close, 20);
break;
case "EMA":
avg = ta.ema(close, 20);
break;
case "WMA":
avg = ta.wma(close, 20);
break;
}
spline(avg, {title: avgType});
}input.source()
Kind: func
Adds a source selector. Allows users to choose which built-in series to use for calculations.
Syntax
input.source(name, defValue) → series
input.source(name, defValue, {options}) → seriesArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | series | Default price series |
Options
| Name | Type | Description |
|---|---|---|
| options? | series[] | List of available sources |
Returns
The selected series.
Example
javascript
// All sources available
const source = input.source("source", close);
// Limited to OHLC only
const priceSource = input.source("price", close, {
options: [open, high, low, close]
});
function onTick() {
spline(ta.sma(source, 20), {title: "SMA"});
}input.color()
Kind: func
Adds a color picker.
Syntax
input.color(name, defValue) → colorArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | color | Default color value |
Returns
The color value of the input.
Example
javascript
const bullColor = input.color("bullColor", color.GREEN);
const bearColor = input.color("bearColor", color.RED);
function onTick() {
spline(close, {color: close > open ? bullColor : bearColor});
}input.session()
Kind: func
Adds a session input. Allows users to define time intervals and days of the week.
Syntax
input.session(name, defValue) → session
input.session(name, defValue, {options, timeZone}) → sessionArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defValue | string | Default session string |
Options
| Name | Type | Description |
|---|---|---|
| options? | string[] | List of available session values |
| timeZone? | string | Time zone used to evaluate the session (see below). Default: UTC |
Time zone
The timeZone option controls how timestamps are interpreted when checking session boundaries. Supported values:
- IANA region name (recommended) - e.g.
"America/New_York","Europe/London","Asia/Tokyo". Handles Daylight Saving Time transitions automatically. - UTC / GMT-prefixed offset - e.g.
"UTC+3","GMT-5","GMT+0530". - Pure offset — e.g.
"+05:30","-08:00","Z"(UTC).
Fixed offsets do not observe DST, use an IANA region name if you need DST-aware behavior.
Short abbreviations like "EST", "PST", "MSK", "IST" are not accepted: they are ambiguous and would silently give wrong results. Use the full IANA name instead: "America/New_York", "Asia/Kolkata", etc.
When the option is omitted, the session evaluates in UTC.
Returns
A session object.
Example
javascript
// Free input
const sess = input.session("Market Hours", "0930-1600:12345");
function onTick() {
const inSession = sess.contains(time);
spline(close, {
title: "Price",
color: inSession ? color.BLUE : color.GRAY
});
}javascript
// Dropdown selector with predefined sessions
const sess = input.session("Session", "0930-1600:12345", {
options: [
"0930-1600:12345", // Regular
"0400-2000:12345", // Extended
]
});
function onTick() {
const inSession = sess.contains(time);
spline(close, {
title: "Price",
color: inSession ? color.BLUE : color.GRAY
});
}javascript
// US Pre-Market session, DST-aware
const pm = input.session("Pre-Market", "0400-0930:12345", {
timeZone: "America/New_York"
});
function onTick() {
const inPm = pm.contains(time);
spline(close, {
title: "Price",
color: inPm ? color.ORANGE : color.GRAY
});
}javascript
// Multiple sessions active at once, sharing a market time zone selected via input.enum
const tz = input.enum("Market", "New York", {
"New York": "America/New_York",
"London": "Europe/London",
"Tokyo": "Asia/Tokyo"
});
const pm = input.session("Pre-Market", "0400-0930:12345", {timeZone: tz});
const rth = input.session("Regular", "0930-1600:12345", {timeZone: tz});
const ah = input.session("After-Hours", "1600-2000:12345", {timeZone: tz});
function onTick() {
let c;
switch (true) {
case pm.contains(time): c = color.ORANGE; break;
case rth.contains(time): c = color.GREEN; break;
case ah.contains(time): c = color.BLUE; break;
default: c = color.GRAY;
}
spline(close, {title: "Price", color: c});
}javascript
// Single session chosen from predefined presets, with a market time zone
const tz = input.enum("Market", "New York", {
"New York": "America/New_York",
"London": "Europe/London"
});
const sess = input.session("Session", "0930-1600:12345", {
timeZone: tz,
options: [
"0400-0930:12345", // Pre-Market
"0930-1600:12345", // Regular
"1600-2000:12345" // After-Hours
]
});
function onTick() {
const inSession = sess.contains(time);
spline(close, {
title: "Price",
color: inSession ? color.GREEN : color.GRAY
});
}input.enum()
Kind: func
Adds a dropdown to choose one of the given options.
Syntax
input.enum(name, defLabel, options) → anyArguments
| Name | Type | Description |
|---|---|---|
| name | string | Unique identifier |
| defLabel | string | Default selected label. Must be a key in options |
| options | object | Enum options: label → value {label: value, ...} |
Returns
The value corresponding to the selected label.
Example
javascript
// Functions
const avgFn = input.enum("method", "SMA", {
"SMA": ta.sma,
"EMA": ta.ema,
"WMA": ta.wma
});
const length = input.double("length", 20);
function onTick() {
const avg = avgFn(close, length);
spline(avg, {title: "MA"});
}javascript
// Numbers
const length = input.enum("length", "Medium", {
"Short": 10,
"Medium": 20,
"Long": 50
});
function onTick() {
const sma = ta.sma(close, length);
spline(sma, {title: "SMA"});
}javascript
// Colors (accessibility)
const palette = input.enum("palette", "Default", {
"Default": {bull: color.GREEN, bear: color.RED},
"Colorblind": {bull: color.BLUE, bear: color.ORANGE},
"Monochrome": {bull: color.WHITE, bear: color.GRAY}
});
function onTick() {
const bull = close > open;
spline(close, {color: bull ? palette.bull : palette.bear});
}javascript
// Objects (presets)
const preset = input.enum("preset", "Default", {
"Default": {fast: 10, slow: 20},
"Scalping": {fast: 5, slow: 10},
"Swing": {fast: 20, slow: 50}
});
function onTick() {
const fastMA = ta.sma(close, preset.fast);
const slowMA = ta.sma(close, preset.slow);
spline(fastMA, {title: "Fast"});
spline(slowMA, {title: "Slow"});
}