Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.darvas.app/llms.txt

Use this file to discover all available pages before exploring further.

Overview

input.* functions declare user-configurable parameters. Each call appears in the Inputs panel as a form control. You must call them at the top level of your script - never inside onBar.
const length = input.int("Length", 14);
const src    = input.source("Source", "close");
const useEma = input.bool("Use EMA", false);

Function reference

input.int(name, default, opts?)
number
Integer spinner. opts: { min, max, step, group }.
const len = input.int("Period", 20, { min: 2, max: 500, step: 1 });
input.float(name, default, opts?)
number
Float spinner. Same opts as input.int.
const mult = input.float("Multiplier", 2.0, { min: 0.1, max: 10, step: 0.1 });
input.bool(name, default, opts?)
boolean
Checkbox toggle.
const showLabels = input.bool("Show labels", true);
input.string(name, default, opts?)
string
Text field. Pass opts.options for a dropdown.
const mode = input.string("Mode", "fast", { options: ["fast", "slow", "adaptive"] });
const note = input.string("Label text", "Signal");
input.color(name, default, opts?)
string
Color picker. Returns a hex color string.
const bullColor = input.color("Bull color", "#22c55eFF");
const bearColor = input.color("Bear color", "#ef4444FF");
input.source(name, default?)
(offset?) => number | null
OHLCV source selector. Returns a function you pass directly to ta.*. The default must be one of "open", "high", "low", "close", "hl2", "hlc3", "ohlc4".
const src = input.source("Source", "close");
// src is now a function: src(0) === ctx.close(0)
ta.ema(src, 20); // pass src directly, do not call it

Form control mapping

Input typeRendered control
input.int / input.floatNumber spinner with optional min/max/step
input.boolCheckbox
input.string with optionsDropdown select
input.string without optionsText field
input.colorColor picker
input.sourceOHLCV source dropdown

Grouping inputs

Use the group option to visually separate inputs in the panel:
const fastLen = input.int("Fast", 12, { group: "MACD" });
const slowLen = input.int("Slow", 26, { group: "MACD" });
const sigLen  = input.int("Signal", 9, { group: "MACD" });
const lineCol = input.color("Line color", "#22c55eFF", { group: "Display" });

The source function pattern

input.source returns an (offset?) => number | null function - the same shape as ctx.close, ctx.open, etc. Pass it directly to ta.*; do not call it yourself:
const src = input.source("Source", "close");

onBar(() => {
  const val = ta.ema(src, 14);  // correct: pass src as a function reference
  // const val = ta.ema(src(), 14);  // WRONG: src() returns a scalar, not a source
});
Calling input.* inside onBar throws a RuntimeError. Move all declarations to the top level.

Script lifecycle

Why top-level code runs once and onBar runs per bar.

Bar context

Built-in OHLCV accessors that share the source function shape.