Inputs

input turns a value in your script into a setting in the header of the chart or DOM it runs on. A trader changes the period of a volume profile from the header instead of opening the code.

Inputs work in indicators, chart styles and ladder styles. Every setting a chart's scripts declare is listed under the header's Settings button (the sliders icon), grouped by script. A value is saved per chart, so two charts can run the same indicator with different periods.

input.number()

input.number(label, default, options?) returns the number picked on this chart, or default until one is picked.

  • min and max clamp it, so the script never sees a value outside them.
  • step is how far the - and + buttons move it. Defaults to 1.
  • Changing the value re-runs the script from the start, with state cleared.
A volume profile per block of candles
const BLOCK_CANDLES = input.number("Period", 40, { min: 5, max: 500, step: 5 })

for (let i = 0; i < candles.length; i += BLOCK_CANDLES) {
  const profile = volumeByPrice(candles.slice(i, i + BLOCK_CANDLES))
  // draw it
}

input.select()

input.select(label, default, options) returns one of options, a list of strings. default must be one of them. Up to four short options show as buttons, more as a list.

Pick which side of the tape to count
const SIDE = input.select("Side", "both", ["both", "buys", "sells"])

for (const trade of tape.tick()) {
  if (SIDE === "buys" && trade.side !== "buy") continue
  if (SIDE === "sells" && trade.side !== "sell") continue
  // count it
}

input.boolean()

input.boolean(label, default) is an Off / On switch.

Let the trader hide the range boxes
const SHOW_BOXES = input.boolean("Boxes", true)

if (SHOW_BOXES) {
  chart.box({ time1, price1: high, time2, price2: low })
}

Labels and the header

  • The label is the setting's name on screen and what the picked value is saved under. Renaming a label resets that setting to its default.
  • A setting appears once the script has run, and disappears when the script stops calling it. Declare inputs at the top of the script, with labels that never change, so they are always there.
  • Picking a different chart or ladder style from the style menu resets that style's settings.
Settings at the top, read like constants below
const PERIOD = input.number("Period", 14, { min: 2, max: 200 })
const SOURCE = input.select("Source", "close", ["open", "high", "low", "close"])
const COLOR = input.select("Color", "blue", ["blue", "orange", "white"])