Skip to content

IndicatorDef

IndicatorDef

An opaque handle to an indicator, produced by defineIndicator() or supplied as a built-in such as RSI. You don’t read its fields — you pass it to api.use() to register the indicator and obtain its output series. The phantom __params and __output fields exist solely to carry the parameter and output types (TParams, TOutput) through the type system.

Signature

export interface IndicatorDef<TParams, TOutput = number> {
readonly __params?: TParams;
readonly __output?: TOutput;
}

Example

indicators/custom-indicator
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 },
});
}
},
};
},
});

An indicator handle returned by defineIndicator.

See also