How limit orders execute in Pine Script strategies
By default, a strategy calculates at bar close and its new order can first fill on the next available tick, usually the next bar open. A buy limit below the current price waits for an eligible price; a buy limit above it is already marketable. Reverse the price relationships for a sell. The emulator does not reconstruct queue priority, order-book depth or partial fills from OHLC bars. Bar Magnifier can add available lower-timeframe price detail, but it does not add a real exchange order book.
| Order type | Function & syntax | Execution condition | Fill price characteristics |
|---|---|---|---|
| Market order | strategy.entry("Long", strategy.long) | Next available tick; next bar open under default close-only calculation | Emulated fill price plus configured slippage; not guaranteed current close |
| Limit order | strategy.entry("Long", strategy.long, limit = 150) | Buy price must be 150 or better after order creation and any verification requirement | If eligible and filled, limit price or better; execution is not guaranteed |
| Stop order | strategy.entry("Long", strategy.long, stop = 160) | Triggers when bar high >= 160 | Activates a market order at the stop; gaps can worsen the fill |
| Stop-limit order | strategy.entry(..., stop = 160, limit = 161) | Triggers at stop; caps execution at limit | Combines breakout trigger with slippage protection ceiling |