Skip to content

limitBuy

ctx.order.limitBuy(price, params)

At a glance — place a pending buy order at price, below the current market: it fills only if price dips down to your level. Returns an OrderTicket you keep to cancel the order if it never fills.

Signature

limitBuy(price: number, params: EntryParams): OrderTicket

Example

order/limit-bracket
import { BollingerBands, defineStrategy, type EntryParams } from '@nexpips/sdk-trading';
/**
* Fade de range sur bandes de Bollinger : un `limitBuy` sur la bande basse
* (repli acheteur) et un `limitSell` sur la bande haute (repli vendeur),
* tous deux visant un retour vers la moyenne.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'M15',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const bb = api.use(BollingerBands, { source: 'close', period: 20, stdDev: 2 });
return {
onBar(ctx) {
if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
const band = bb.at(0);
const entry: EntryParams = {
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'price', value: band.middle },
};
ctx.order.limitBuy(band.lower, entry);
ctx.order.limitSell(band.upper, entry);
},
};
},
});

Fade a range: limitBuy on the lower band, limitSell on the upper.

To know

  • A limitBuy priced above the market is a code bug and throws StrategyInvariantError.
  • Check ctx.position.hasPendingOrder before placing another order.

See also