Exciting Update: Version 1.0.6 is now available, introducing Direct Pine Script Mode, Pine Logs Runtime Bridge, Zero-Repaint Linting, Source Maps, Intrabar MFE/MAE Stats, and expanded Pine v5/v6 Transpiler Parity. Read more
Version: 1.0.6

User Inputs & Settings UI

The BacktestX script engine allows you to define customizable settings that automatically generate a User Interface (UI) for your indicator. This lets end-users tweak parameters without editing the raw code.

Dynamic Inputs Architecture

The BacktestX script engine dynamically builds the Inputs Tab in the indicator settings dialog when your script declares input parameters using ctx.input(key, defaultValue, options) or the input.* helpers.

💡 Important Architecture Rule: If your script hardcodes values without calling ctx.input() or input.*, the chart properties modal will display "This indicator has no input settings." Always declare your user-adjustable variables with ctx.input() outside loops.
BacktestX Script
// Define customizable settings
const length = ctx.input('length', 14, { title: 'Length', type: 'int', min: 1, max: 200 });
const source = ctx.input('source', 'Close', {
  title: 'Source',
  type: 'string',
  options: ['Close', 'Open', 'High', 'Low', 'HL2', 'HLC3', 'OHLC4']
});
const offset = ctx.input('offset', 0, { title: 'Offset', type: 'int', min: -500, max: 500 });

Input Options Specification

The third parameter of ctx.input() accepts an options object with the following schema:

Option Key Type Default Description
title string key User-facing label displayed next to the input in the settings dialog.
type 'int' | 'float' | 'string' | 'bool' 'string' Determines widget control (stepper, decimal input, dropdown, or checkbox).
min number -Infinity Minimum allowable value for numeric inputs ('int', 'float').
max number Infinity Maximum allowable value for numeric inputs ('int', 'float').
step number 1 (or 0.1) Increment/decrement step size when clicking arrows or dragging.
options Array<string> undefined Array of choices. Automatically converts a string input into a dropdown select box.
group string undefined Renders a collapsible section header grouping related inputs together.
inline string undefined Places multiple inputs side-by-side on the same row sharing this inline ID.

Pine Script Input Helper Aliases & Named Arguments (v1.0.6)

For Pine Script developers and Direct Pine Mode scripts, BacktestX supports input.* helpers as well as quote- and comment-safe out-of-order named argument reordering (e.g., ta.ema(length=20, source=close) or input.int(title="Length", defval=14)):

BacktestX Script
// Integer input (positional or out-of-order named args)
const length = input.int(14, "Length", { min: 1, max: 200, step: 1 });

// Float input
const mult = input.float(2.0, "Multiplier", { min: 0.1, max: 10.0, step: 0.1 });

// String input / Dropdown
const src = input.string("Close", "Source", { options: ["Close", "Open", "High", "Low", "HL2", "HLC3", "OHLC4"] });

// Boolean checkbox
const showBands = input.bool(true, "Show Outer Bands");

// Color picker
const customColor = input.color("#2962ff", "Line Color");

Standard Price Source Extraction Pattern

In Direct Pine Mode (v1.0.6), built-in derived price series hl2, hlc3, ohlc4, and hlcc4 are injected natively on every bar. In raw JavaScript mode, use this canonical source resolver helper for user-configurable source inputs:

BacktestX Script
// 1. Declare the source input dropdown
const source = ctx.input('source', 'Close', {
  title: 'Source',
  type: 'string',
  options: ['Close', 'Open', 'High', 'Low', 'HL2', 'HLC3', 'OHLC4']
});

// 2. Resolver helper function
const getSourceValue = (bar) => {
  if (!bar) return 0;
  const s = String(source).toLowerCase();
  if (s === 'open') return bar.open;
  if (s === 'high') return bar.high;
  if (s === 'low') return bar.low;
  if (s === 'hl2') return (bar.high + bar.low) / 2;
  if (s === 'hlc3') return (bar.high + bar.low + bar.close) / 3;
  if (s === 'ohlc4') return (bar.open + bar.high + bar.low + bar.close) / 4;
  return bar.close; // default fallback
};

// 3. Extract mapped scalar array for ctx.ta functions
const srcSeries = (ctx.bars || []).map(getSourceValue);

Offset Shifting Pattern

To allow users to displace/shift an indicator line forward or backward in time, declare an offset input and map the calculated series:

BacktestX Script
const offset = ctx.input('offset', 0, { title: 'Offset', type: 'int', min: -500, max: 500 });

const rawData = ctx.ta.ema(srcSeries, length);

// Shift series by offset bars
const plotData = offset === 0 
  ? rawData 
  : rawData.map((val, idx, arr) => arr[idx - offset] ?? null);