🎛️Script Inputs
Inputs are controls that let users configure parameters of your indicator or strategy. For example: a period for a moving average, a color for a line, or a switch to enable/disable a feature.
Important:
All inputs must be declared only inside the
initcontrol block.Always start with
input.followed by the method you want to use (e.g.,input.int,input.bool,input.color).
Inputs API
File:
inputs‑indicator.api.tsProvides UI controls so users can configure parameters.
Example
//@version=1
// This is a template for a custom indicator. You can use this as a starting
// point to create your own custom indicator.
// This is the setup function.
// Here you can define the input parameters for the indicator.
init = () => {
input.bool('show draws', true, 'show');
input.bool('extend fvg', true, 'extend');
input.int(
'SMA Length',
14,
undefined, // auto id: "smalength"
1, // min
200, // max
1, // step
'Number of bars used to calculate SMA',
'Moving Averages',
'ma-row'
);
input.float(
'ATR Multiplier',
1.5,
undefined, // auto id: "atrmultiplier"
0.1, // min
10, // max
0.1, // step
'Factor applied to ATR for stop calculation',
'Risk Management',
'risk-row'
);
// Example: Notes field
input.textarea(
'Strategy Notes',
'Enter your notes here...',
undefined,
'Add optional comments or explanations',
'General Settings'
);
// Example: List of symbols
input.textarea(
'Watchlist Symbols',
'AAPL, MSFT, TSLA',
undefined,
'Comma-separated list of tickers',
'Symbols'
);
input.time(
'Session Start',
930, // default: 9:30
undefined, // auto id: "sessionstart"
0, // min (0 = 00:00)
2359, // max (2359 = 23:59)
'Time when trading session begins',
'Sessions',
'session-row'
);
// Example: Trading session end time
input.time(
'Session End',
1600, // default: 16:00
undefined,
0,
2359,
'Time when trading session ends',
'Sessions',
'session-row'
);
input.session(
'Trading Session',
'0930-1600',
undefined, // auto id: "tradingsession"
['0930-1600', '0800-1200'], // dropdown options
'Choose the active trading hours',
'Sessions',
'session-row'
);
input.color(
'Line Color',
color.blue, // default color
undefined,
'Styles',
'Choose the line color'
);
// Example: Pick a custom RGBA color
input.color(
'Background',
{ r: 255, g: 200, b: 50, a: 0.5 }, // semi-transparent orange
undefined,
'Styles',
'Background color with transparency'
);
}
// This is the main function. It is called every time a new candle is received.
// Here you can calculate the indicator values and draw the indicator on the chart.
onTick = (length, _moment, _, ta, inputs) => {
}; Warning
Declaring inputs outside of
initor forgetting theinput.prefix will cause errors and your indicator may fail to load or get a result you don't expect.
✅ Good Practice
Group inputs by category (e.g., calculation parameters, colors, display options) and use descriptive names. This makes it easier for users to understand and adjust the settings.
Last updated