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, });
| Option | Type | Required | Description |
|---|---|---|---|
type | 'int' | Yes | Integer parameter |
label | string | No | Display label in the UI |
description | string | No | Tooltip text |
default | number | Yes | Default value |
min | number | No | Minimum allowed value |
max | number | No | Maximum allowed value |
step | number | No | Step size (used during optimization grid) |
optimize | boolean | No | Whether this parameter can be optimized |
group | string | No | Group 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'], });
| Option | Type | Required | Description |
|---|---|---|---|
type | 'string' | Yes | String parameter |
default | string | Yes | Default selected value |
options | string[] | No | Allowed 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
typeand adefaultvalue typemust be one of:'int','float','string','boolean'- If
minis provided butdefaultis not, the engine will useminas the fallback - Duplicate parameter names will overwrite silently — use unique names
parametersdefineparamctx.paramintfloatstringbooleantype