DocsErrors

Contract Errors

Every QSL strategy must export specific lifecycle functions. Contract errors are raised when required functions are missing.

Required Functions

FunctionStatusPurpose
define(ctx)RequiredDeclare parameters
init(ctx)RecommendedSet up indicators and state
onBar(ctx, i)RequiredProcess each candle

Error: missing_define

Error: Strategy must export a define() function

Cause: Your code does not contain a function define(ctx) declaration.

Fix: Add a define() function, even if you have no parameters:

function define(ctx) { // No parameters needed for this strategy }

Error: missing_onbar

Error: Strategy must export an onBar() function

Cause: Your code does not contain a function onBar(ctx, i) declaration.

Fix: Add your trading logic inside onBar():

function onBar(ctx, i) { // Your trading logic here }

Warning: missing_init

Warning: Strategy does not export an init() function

init() is not strictly required, but without it you cannot declare indicators or initialise state. Most strategies need it.

function init(ctx) { ctx.indicator('sma', 'SMA', { period: ctx.p.period }); }

Function Naming

Functions must use these exact names. Common mistakes:

// Wrong — these will NOT be detected function Define(ctx) { } // uppercase D function on_bar(ctx, i) { } // underscore function setup(ctx) { } // wrong name const onBar = (ctx, i) => {} // arrow function (may not be detected) // Correct function define(ctx) { } function init(ctx) { } function onBar(ctx, i) { }
contractmissingdefineinitonBarlifecyclerequired