DocsType Reference
Context Objects
Each lifecycle function receives a different context object. The context provides access to the APIs available at that stage.
DefineContext
Passed to define(ctx). Only has the param() method.
interface DefineContext { param(name: string, options: ParamDefinition): void; }
InitContext
Passed to init(ctx). Provides parameter values, indicator declaration, and state.
interface InitContext { readonly p: Record<string, number | string | boolean>; indicator(name: string, type: IndicatorType, options: IndicatorOptions): void; state: Record<string, unknown>; }
| Property | Description |
|---|---|
ctx.p | Read-only parameter values (set before init runs) |
ctx.indicator() | Declare a host-computed indicator |
ctx.state | Mutable object for tracking state between bars |
OnBarContext
Passed to onBar(ctx, i). Full access to indicators, price data, orders, and state.
interface OnBarContext { readonly p: Record<string, number | string | boolean>; readonly ind: Record<string, number[]>; readonly open: number[]; readonly high: number[]; readonly low: number[]; readonly close: number[]; readonly volume: number[]; readonly time: number[]; readonly order: OrderAPI; pos(symbol: string): Position; state: Record<string, unknown>; }
| Property | Description |
|---|---|
ctx.p | Parameter values |
ctx.ind | Computed indicator data arrays (multi-output indicators are flat suffixed keys, not nested objects - see Indicator Results) |
ctx.open / ctx.high / ctx.low / ctx.close / ctx.volume / ctx.time | OHLCV price data - flat arrays directly on ctx. There is no ctx.series |
ctx.order | Order execution API |
ctx.pos() | Reports position size, but does NOT track real position state during a backtest - see Order & Position Types |
ctx.state | Mutable state object |
contextDefineContextInitContextOnBarContextctxtypes