A breakout strategy may identify a valid signal at a closing price of 100, only to enter at 103 after an overnight gap. A market order prioritizes execution rather than price. A capped buy limit is an alternative when the strategy is willing to miss a trade rather than chase an unfavorable opening price.
Define the price and lifetime separately
For a confirmed close above the preceding 20-bar high, calculate a maximum entry price of 101% of the signal close, rounded down to the instrument tick. At a signal close of 100, with a compatible tick size, the cap is 101. A next open of 100.50 may permit an immediate fill; an open of 103 does not. If price subsequently falls to the limit during the next bar, the order may still fill. This is a price ceiling, not an opening-gap rejection rule.

Pine Script v6 implementation
The example uses a single long position and one-unit orders. It cancels an unfilled entry at the next confirmed bar close, then permits a fresh independent breakout. A simple close below the 10-bar SMA supplies an illustrative exit, not a protective stop. The prior-bar channel avoids including the current high in its own breakout threshold.
//@version=6
strategy("Bounded breakout entry", overlay=true,
pyramiding=0, process_orders_on_close=false)
float ceiling = ta.highest(high, 20)[1]
bool breakout = ta.crossover(close, ceiling)
var int submitted = na
if barstate.isconfirmed
if not na(submitted) and bar_index > submitted
strategy.cancel("L")
submitted := na
if breakout and strategy.position_size == 0 and na(submitted)
float cap = math.floor(close * 1.01 / syminfo.mintick) * syminfo.mintick
strategy.entry("L", strategy.long, qty=1, limit=cap)
submitted := bar_index
if strategy.position_size > 0 and close < ta.sma(close, 10)
strategy.close("L")
Understand the emulator
With process_orders_on_close disabled, a newly generated order normally cannot fill before the next available tick. Historical bars are modeled from available OHLC data; Bar Magnifier can improve intrabar modeling where lower-timeframe data is available. A limit order may fill at a better price, and the limit verification setting can require price to move beyond the limit before the emulator considers it filled. None of these assumptions establishes live queue priority. A cancellation at the next bar close cannot undo a fill earlier in that bar.
Testing checklist
| Next bar | Expected behavior |
|---|---|
| Open 100.50 | Eligible for fill at open |
| Open 103, low 102 | No fill; cancel at close |
| Open 103, low 100 | Possible intrabar limit fill |
Compare the capped strategy with a market-entry baseline using identical signals, sizing and exit rules. Record fill rate, missed breakouts, adverse selection, commissions and drawdown. Test multiple instruments and out-of-sample periods. For live alert routing, the external order manager must implement actual order expiry, fill reconciliation and rejection handling; TradingView emulator fills are not broker confirmations. A price cap does not limit subsequent losses, and this educational example has no hard protective stop. It has not been compiled or backtested here. Trading involves risk of loss.
Official reference: Pine Script strategies documentation.
To adapt this free strategy idea, contact us about Custom TradingView strategy Development Services.