DocsParameters

Defining Parameters

Parameters let you control strategy behaviour without editing code. They are declared inside define() and accessed in init() and onBar() via ctx.p.

Declaring a Parameter

function define(ctx) { ctx.param('period', { type: 'int', label: 'EMA Period', description: 'Look-back period for the EMA indicator', default: 14, min: 5, max: 200, step: 1, optimize: true, group: 'Indicators', }); }

Parameter Types

int

Integer values — best for look-back periods, thresholds, and counts.

ctx.param('period', { type: 'int', label: 'Period', default: 14, min: 5, max: 200, step: 5, optimize: true, });
OptionTypeRequiredDescription
type'int'YesInteger parameter
labelstringNoDisplay label in the UI
descriptionstringNoTooltip text
defaultnumberYesDefault value
minnumberNoMinimum allowed value
maxnumberNoMaximum allowed value
stepnumberNoStep size (used during optimization grid)
optimizebooleanNoWhether this parameter can be optimized
groupstringNoGroup label for UI organization

float

Decimal values — useful for multipliers, thresholds, and percentages.

ctx.param('riskPercent', { type: 'float', label: 'Risk %', default: 2.0, min: 0.5, max: 10.0, step: 0.5, optimize: true, });

Same options as int but accepts decimals.

string

Enum/select values — ideal for choosing between modes or variants.

ctx.param('source', { type: 'string', label: 'Price Source', default: 'close', options: ['open', 'high', 'low', 'close', 'hl2', 'hlc3'], });
OptionTypeRequiredDescription
type'string'YesString parameter
defaultstringYesDefault selected value
optionsstring[]NoAllowed values (displayed as a dropdown)

boolean

Toggle values — for enabling/disabling features.

ctx.param('useTrailingStop', { type: 'boolean', label: 'Trailing Stop', description: 'Enable ATR-based trailing stop', default: false, });

Accessing Parameters

Parameters are available in init() and onBar() via ctx.p:

function init(ctx) { ctx.indicator('ema', 'EMA', { period: ctx.p.period, source: 'close' }); } function onBar(ctx, i) { const threshold = ctx.p.riskPercent / 100; if (ctx.p.useTrailingStop) { // trailing stop logic } }

Parameters are read-only at runtime. All values are set before the backtest begins.

Validation Rules

  • Every parameter must have a type and a default value
  • type must be one of: 'int', 'float', 'string', 'boolean'
  • If min is provided but default is not, the engine will use min as the fallback
  • Duplicate parameter names will overwrite silently — use unique names
parametersdefineparamctx.paramintfloatstringbooleantype