Skip to content

Strategy

Strategy

The opaque, branded value returned by defineStrategy(). You never construct it directly or read its fields — you simply export default it from your bot file so the runtime can pick it up. The __brand tag exists only to prevent plain objects from being mistaken for a validated strategy at compile time.

Signature

export interface Strategy {
readonly __brand: 'Strategy';
}

Example

order/market-buy-simple
import { defineStrategy } from '@nexpips/sdk-trading';
/**
* Acheter au marché si on est flat, avec un stop-loss à 20 pips.
*
* Pattern : entrée propre — vérifier `hasPendingOrder` ET `isFlat`
* pour éviter d'envoyer un ordre alors qu'un précédent est encore
* en attente de confirmation broker.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: {
maxRiskPercentPerTrade: 1,
maxOpenPositions: 1,
maxDailyLossPercent: 5,
},
setup: () => ({
onBar(ctx) {
if (!ctx.position.isFlat) return;
if (ctx.position.hasPendingOrder) return;
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'pips', value: 20 },
takeProfit: { type: 'rr', value: 2 },
});
},
}),
});

Exporting the strategy returned by defineStrategy.

See also