How limit orders execute in Pine Script strategies
A limit order specifies the maximum price you are willing to pay for a buy, or the minimum price you will accept for a sell. Unlike market orders (which execute immediately at current market price), a limit order waits in the order book. In Pine Script, when you specify limit = targetPrice in strategy.entry() or strategy.order(), the broker emulator checks subsequent price bars. If market low dips down to touch or penetrate your limit price, the order fills at your exact limit price (or better).
| Order type | Function & syntax | Execution condition | Fill price characteristics |
|---|---|---|---|
| Market order | strategy.entry("Long", strategy.long) | Executes on open of next bar | Fills at current market price with potential slippage |
| Limit order | strategy.entry("Long", strategy.long, limit = 150) | Fills only when bar low <= 150 | Guaranteed fill at limit price or better (zero adverse slippage) |
| Stop order | strategy.entry("Long", strategy.long, stop = 160) | Triggers when bar high >= 160 | Turns into market order when price breaks through resistance |
| Stop-limit order | strategy.entry(..., stop = 160, limit = 161) | Triggers at stop; caps execution at limit | Combines breakout trigger with slippage protection ceiling |