IndicatorContext
IndicatorContext
The context passed to a custom indicator’s update() callback. It exposes the resolved params for this instance, the raw series of market data to compute over, and a use() method for composing other indicators inside your own. Parameterized by TParams, the shape of the indicator’s configuration.
Signature
export interface IndicatorContext<TParams> { readonly params: TParams; readonly series: MarketSeries; use<P, O>(def: IndicatorDef<P, O>, params: P): Series<O>;}Example
import { defineIndicator, defineStrategy } from '@nexpips/sdk-trading';
/** * Indicateur custom via `defineIndicator` : l'amplitude (range) de la barre * courante. `update` est appelé une fois par barre clôturée et reçoit un * `IndicatorContext`. L'engine accumule les retours dans une `Series`. */const BarRange = defineIndicator<{ history?: number }, number>({ name: 'BarRange', warmup: () => 1, update: (ctx) => ctx.series.high.at(0) - ctx.series.low.at(0),});
export default defineStrategy({ symbol: 'EURUSD', timeframe: 'H1', risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 }, setup: (api) => { const range = api.use(BarRange, {});
return { onBar(ctx) { if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
if (range.at(0) > 0) { ctx.order.marketBuy({ riskPercent: 1, stopLoss: { type: 'pips', value: 20 }, takeProfit: { type: 'rr', value: 2 }, }); } }, }; },});Reading params and series inside a custom indicator.