Skip to content

marketSell

ctx.order.marketSell(params)

At a glance — send a sell order at market, opening a short position. Takes the same EntryParams as marketBuy (a stopLoss is mandatory). The position only exists once the broker confirms the fill asynchronously via onOrderFilled; until then ctx.position.hasPendingOrder is true.

Signature

marketSell(params: EntryParams): OrderTicket

Example

order/sell-short
import { defineStrategy, EMA } from '@nexpips/sdk-trading';
/**
* Vente à découvert : `marketSell` ouvre une position short au marché. Les
* `EntryParams` sont identiques à un achat (un `stopLoss` reste obligatoire).
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const ema = api.use(EMA, { source: 'close', period: 50 });
return {
onBar(ctx) {
if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
// Clôture sous l'EMA(50) → biais baissier → vente au marché.
if (ctx.series.close.at(0) < ema.at(0)) {
ctx.order.marketSell({
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
}
},
};
},
});

Sell short when price closes below the EMA(50).

To know

  • The returned OrderTicket is a correlation handle, not a fill — react to the outcome in onOrderFilled / onOrderRejected.
  • Missing stopLoss or breaching the risk config throws StrategyInvariantError synchronously.

See also