Skip to content

RiskConfig

RiskConfig

The risk guardrails declared on your StrategyDefinition. The engine enforces them on every order: maxRiskPercentPerTrade caps per-trade exposure, maxOpenPositions limits concurrency, maxDailyLossPercent halts trading after a daily drawdown, and the optional maxConsecutiveRejects stops the bot after repeated broker rejections.

Signature

export interface RiskConfig {
maxRiskPercentPerTrade: number;
maxOpenPositions: number;
maxDailyLossPercent: number;
maxConsecutiveRejects?: number;
}

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 },
});
},
}),
});

Declare risk limits enforced by the engine.

See also