Skip to content

ModifyParams

ModifyParams

The arguments for ctx.order.modifyPosition, used to adjust an open trade’s protective levels. Both stopLoss and takeProfit are optional PriceLevel values — supply only the ones you want to change, for instance to trail a stop.

Signature

export interface ModifyParams {
stopLoss?: PriceLevel;
takeProfit?: PriceLevel;
}

Example

order/limit-and-cancel
import { defineStrategy, type OrderTicket } from '@nexpips/sdk-trading';
/**
* Ordres en attente : poser un `limitBuy`, l'annuler (`cancel`) s'il n'est
* pas rempli en quelques barres, et resserrer le stop d'une position ouverte
* (`modifyPosition`). Le `limitBuy` renvoie un `OrderTicket` opaque à conserver.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'M15',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: () => {
let pending: OrderTicket | null = null;
let barsWaiting = 0;
return {
onBar(ctx) {
if (ctx.position.hasPendingOrder && pending) {
barsWaiting += 1;
if (barsWaiting > 3) {
ctx.order.cancel(pending);
pending = null;
barsWaiting = 0;
}
return;
}
if (ctx.position.isLong) {
ctx.order.modifyPosition({ stopLoss: { type: 'pips', value: 10 } });
return;
}
if (ctx.position.isFlat) {
const limitPrice = ctx.bar.close - 0.001;
pending = ctx.order.limitBuy(limitPrice, {
riskPercent: 1,
stopLoss: { type: 'pips', value: 20 },
takeProfit: { type: 'rr', value: 2 },
});
barsWaiting = 0;
}
},
};
},
});

Adjust the stop-loss or take-profit of an open position.

See also