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): OrderTicketExample
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
OrderTicketis a correlation handle, not a fill — react to the outcome inonOrderFilled/onOrderRejected. - Missing
stopLossor breaching theriskconfig throwsStrategyInvariantErrorsynchronously.
See also
marketBuy— the long counterpartstopSell·limitSellEntryParams