Version: 1.0.1
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.
Using ctx.input()
You define a configurable input using the ctx.input(key, defaultValue, options) method. This should be called outside of your rendering loop so it runs once during initialization.
// Define an integer input for SMA length
const smaLength = ctx.input('sma_len', 14, {
title: 'SMA Period',
type: 'int',
min: 1,
max: 200,
step: 1,
group: 'Moving Averages'
});
// Use the dynamically assigned value
const smaLine = ctx.ta.sma(ctx.bars.map(b => b.close), smaLength);
ctx.plot(smaLine, { color: '#2962ff' });
Supported Input Types
'int': Integer slider/input. Acceptsmin,max, andstep.'float': Decimal slider/input. Acceptsmin,max, andstep.'bool': Renders as a checkbox toggle.'string': Renders as a text input or dropdown (ifoptionsarray is provided).