Skip to content

SetupApi

SetupApi

The api argument passed to your strategy’s setup() function. Call use() to register an indicator and receive its output Series, and reach for input to declare tunable parameters. Everything here runs once during the setup phase, before the first bar — registering indicators or inputs later is not allowed.

Signature

export interface SetupApi {
use<P, O>(indicator: IndicatorDef<P, O>, params: P): Series<O>;
input: InputApi;
}

Example

indicators/ema-crossover
import { crossedOver, crossedUnder, defineStrategy, EMA } from '@nexpips/sdk-trading';
/**
* Croisement de moyennes exponentielles. Golden cross (EMA rapide passe
* au-dessus de la lente) → entrée ; death cross → sortie. Montre `EMA`,
* `crossedOver` et `crossedUnder`.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const fast = api.use(EMA, { source: 'close', period: 12 });
const slow = api.use(EMA, { source: 'close', period: 26 });
return {
onBar(ctx) {
if (ctx.position.isFlat && !ctx.position.hasPendingOrder && crossedOver(fast, slow)) {
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
return;
}
if (ctx.position.isLong && crossedUnder(fast, slow)) {
ctx.order.closePosition('ema death cross');
}
},
};
},
});

Registering two EMAs during setup.

See also