Concepts
Inputs
Declare the settings of a script. Values are saved per chart.
inputs declares the script's settings. The settings dialog is generated from them, values are saved per chart, and ctx.inputs holds the current values.
inputs: {
length: input.int({ default: 20, min: 1, max: 500, label: "Length" }),
source: input.select({ default: "Close", options: ["Open", "High", "Low", "Close"] }),
line: input.lineStyle({ default: { color: "#f59e0b", width: 2 }, label: "Line", group: "Style" }),
},ctx.inputs.length is a number, ctx.inputs.source is "Open" | "High" | "Low" | "Close", ctx.inputs.line passes to g.line as is.
Builders
| Builder | Value | Options |
|---|---|---|
input.int, input.float | number | min, max, step |
input.bool | boolean | |
input.string | string | |
input.color | CSS color | |
input.select | union of options | options |
input.price | price | number field |
input.time | epoch ms | date and time field |
input.symbol | symbol code, e.g. "NQ" | |
input.timeframe | Timeframe, e.g. "5m" | |
input.lineStyle | LineStyle | solid, dashed, dotted |
All take label (the key when omitted), group (inputs with the same group share a section) and tooltip.
Changes restart
Changing an input restarts the script: state is dropped and history replays. So inputs can shape subscribe, e.g. trades({ minSize: ctx.inputs.minSize }).
An invalid saved value, e.g. out of min/max, falls back to its default and shows as an error.