ctx.order.limit()
Place a limit order that fills only when price reaches a specified level.
Signature
ctx.order.limit(symbol, quantity, price, metadata?)
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Asset symbol (typically 'ASSET') |
quantity | number | Position size (positive for long, negative for short) |
price | number | The limit price at which the order should fill |
metadata | object | Optional order metadata |
How Limit Orders Work
Unlike market orders which fill at the next bar's open, limit orders only fill when the price reaches your specified level:
- Long limit: Fills when price drops to or below the limit price
- Short limit: Fills when price rises to or above the limit price
If the price never reaches the limit level, the order is not executed.
Examples
Buy the dip
function onBar(ctx, i) { const pos = ctx.position('ASSET'); const close = ctx.series.close[i]; const atr = ctx.ind.atr[i]; if (pos.qty === 0) { // Place limit order 1 ATR below current close const limitPrice = close - atr; ctx.order.limit('ASSET', 1, limitPrice, { signal: 'buy', reason: 'atr_dip' }); } }
Support-level entry
function onBar(ctx, i) { const pos = ctx.position('ASSET'); const support = ctx.ind.donchian_lower[i]; if (pos.qty === 0) { // Enter long at Donchian lower band (support) ctx.order.limit('ASSET', 1, support, { signal: 'buy', reason: 'support_entry' }); } }
Limit vs Market
function onBar(ctx, i) { // Market order: fills at next bar's open regardless of price ctx.order.market('ASSET', 1, { signal: 'buy' }); // Limit order: only fills if price reaches the specified level ctx.order.limit('ASSET', 1, 50000, { signal: 'buy' }); }
Related
- ctx.order.market() — Market orders (immediate fill)
- ctx.order.close() — Close position
- ctx.order.reduce() — Partial exit
orderslimitentrypriceqsl