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[] | MACDResult | BBandsResult | DonchianResult | StochResult>; readonly series: Series; readonly order: OrderAPI; readonly barIndex: number; position(symbol: string): Position; state: Record<string, unknown>; }
| Property | Description |
|---|---|
ctx.p | Parameter values |
ctx.ind | Computed indicator data arrays |
ctx.series | OHLCV price data |
ctx.order | Order execution API |
ctx.barIndex | Current bar index (same as i) |
ctx.position() | Current position for a symbol |
ctx.state | Mutable state object |
contextDefineContextInitContextOnBarContextctxtypes