How do overnight gaps affect stop-loss fills in a backtest?
An overnight gap can carry price past a stop, so a backtest may fill at the next opening price instead of the stop level.
On this page
- What happens when price gaps past a stop?
- Does the same issue apply to a short position?
- Is a stop price the same as an exit price?
- How can you identify a gap-related exit?
- Why do sessions and chart data matter?
- Can more detailed bars remove the uncertainty?
- Where does slippage fit into the comparison?
- How can you compare stop settings by hand?
- What should you record when comparing runs?
- What can this check establish?
- Sources
Key takeaways
- A stop level is a trigger, not a fixed exit price.
- Check whether the stop was active before the gap and compare its level with the next opening price.
- Session settings, chart data and fill assumptions affect how a backtest represents gaps.
- A simulated opening-price fill does not establish the price available in live trading.
What happens when price gaps past a stop?
An overnight gap can carry the next available chart price past a stop-loss level, so a backtest may record an exit away from the intended stop. A stop-loss is an order meant to close a position when price reaches a specified level, so the level describes when the exit is triggered rather than necessarily fixing the price at which it is recorded. The gap is the difference between the previous bar’s closing price and the next bar’s opening price, so examining it means comparing the end of one displayed bar with the start of the bar that follows.
For a long position, imagine that the prior close is above an active sell stop, but the next bar opens below it, leaving the stop level between the prices shown on the chart. The test may record an exit at the opening price rather than at the stop, with a larger distance between entry and exit than the stop appeared to set.
TradingView’s strategy manual, checked 2026-11-25, says its emulator fills a price-based order crossed in the gap between bars at the following bar’s opening price. This simulation rule is not evidence that an actual order would have filled at that precise opening price, because a historical chart does not reproduce all the conditions an order might meet, and the simulated fill should be understood in that light. The order must also have been active when its level was crossed, so its timing belongs in the review.
Does the same issue apply to a short position?
The direction reverses for a short position, which benefits from a fall in price and loses value when price rises, so the move to examine runs in the opposite direction from the move affecting a long position. A protective stop for that position would normally be a buy order above the market, so an opening price above an already active stop can produce a less favorable simulated exit than the stop level itself.
For a long position, the concerning gap is downward through a sell stop. For a short position, it is upward through a buy stop. In either case, compare the stop with the next opening price in the direction that makes the exit less favorable, rather than assuming the stop itself fixes the maximum distance between entry and exit.
Not every overnight move crosses the stop, and a favorable gap is a different case. Price can also reach a stop after the open, within a bar, rather than cross it in the gap between bars, so the timing of the move matters when you review the fill.
The same word can describe an entry order as well as an exit order. Here the subject is a stop used to close an existing position, so check the trade direction and order details before assuming that a chart marker represents the protective exit.
Is a stop price the same as an exit price?
The stop price is the level that activates an order, while the fill is the price recorded when the order is completed, and the distinction matters when you inspect an exit in a backtest. Those values answer different questions: one describes the trigger set by the order, and the other describes the price assigned to the exit, so they should be kept separate when you examine the trade.
For a stock stop order, FINRA’s explanation, checked 2026-11-25, says the order becomes a market order when the stop price is reached and that the execution price can differ from the stop price. A market order seeks execution rather than a particular price, and a fast move can leave the available price away from the trigger, so the trigger is not a fixed cap on the distance from entry to exit.
A backtest represents that event using its data and fill rules, so its recorded exit reflects the information and assumptions in the test rather than a complete record of every condition an actual order might face. A stop-limit order has a different trade-off: it combines a trigger with a limit on the acceptable price, so it may remain unfilled if the available price does not meet that limit.
Do not treat a stop-limit as an assured exit or an ordinary stop as an assured price, because the type of order changes what its specified price means and how to interpret an exit in the test. When comparing a script with an intended order, inspect the order type rather than relying on the exit label alone, since the label does not by itself establish that the script represents the intended order.
How can you identify a gap-related exit?
Start with an individual trade that closed near a session open, and record its direction, entry time, exit time and reported exit price, keeping these details together so you can examine the exit against the chart around that session. Then inspect the chart around the exit, noting the prior close, the following open and the stop level that applied before the gap, so you can compare the trigger with the displayed prices.
The key question is whether the position and its stop were already active before the interval without chart prices. If the stop was created only after the new bar began, an opening price beyond the intended level does not by itself prove that an existing stop was crossed in the gap, so check when the order was created before drawing that conclusion.
A script that changes its stop needs a check of the level in force at that moment, not just the level visible later, because the later value does not by itself establish what the order specified before the gap. A useful note separates observation from interpretation: record where the chart opened, where the simulated exit appeared and what the report or script establishes about the order’s timing.
If the order history is unclear, label the cause as uncertain rather than assuming the gap alone explains the exit, and distinguish what the chart shows from what remains unknown about the order itself. A separate rule might have closed the position while a gap happened nearby, so inspect the timing and order details before assigning the exit to the protective stop.
Why do sessions and chart data matter?
A trading session is the span of time included as a market’s trading period. The bars visible on a chart depend on the data and session selected, so an overnight move may appear as a gap in one view and as a sequence of smaller moves in another.
Neither view should be assumed to show every price at which an order could have traded, even if it provides a useful way to examine the movement shown around the session open, so keep that limit in mind when reading the chart. The available data may exclude some activity, and the order under review may not have been eligible to act throughout the interval that appears empty on the chart.
Note the symbol, session, chart timeframe and time zone alongside the trade. A timeframe is the period represented by each chart bar, and recording it helps another reader find the interval and understand what its opening and closing prices represent.
For a fair comparison, keep the data view consistent while checking stop behavior. If you change the session or timeframe, record the change and inspect the affected trades again: a different exit may reflect different visible prices or a different calculation point, rather than a change in the stop rule itself.
The guide to choosing a backtest date range covers the period used for a test. The narrower question here is whether the selected data makes the gap and the active order visible enough to examine the simulated fill, rather than simply showing a price move near the time the position was closed in the test.
Can more detailed bars remove the uncertainty?
A bar summarizes a period with an open, high, low and close. Those prices do not show every transaction or establish the exact route price took between the high and low, so a test using only that summary needs assumptions about the order in which events occurred.
TradingView’s Bar Magnifier page, checked 2026-11-25, describes using lower-timeframe prices during backtesting to inspect movement within a chart bar. This can change the simulated sequence of an entry and exit when finer data is available, making a comparison of the same trade with and without that detail useful.
Keep the other settings unchanged during that comparison, and check the coverage of the detailed data before treating a report change as one that applies across the entire test. Finer bars do not establish prices during an interval for which no relevant data is available, and they do not reconstruct every condition an actual order would have met.
If the stop was crossed between available bars, distinguish that gap from uncertainty about movement inside a bar, since the available data leaves different questions about where and when the crossing occurred, depending on whether it took place between bars or within one. Both can affect an exit, but they ask different questions about the information available to the simulation: one concerns the interval between available bars, while the other concerns the movement represented within a bar in the data used for the test.
Where does slippage fit into the comparison?
Slippage is a difference between a reference price and the price at which an order fills, so it describes a comparison between those prices rather than the distance between the close and open of chart bars. It is distinct from a gap: the gap describes a change between displayed prices, while slippage describes a difference in the execution price, so inspect both before attributing the whole difference to either one.
TradingView’s strategy properties page, checked 2026-11-25, says its slippage property adds a specified number of price ticks to the fill price of market or stop orders. A tick is a price increment. The setting is a model input, not a record of the prices or quantities available during a particular opening, so its use in the test does not establish the conditions an actual order would have encountered at that time.
Commission is a trading fee, and it is another separate item in the accounting. Keep the fee and slippage assumptions visible when comparing exits, rather than folding them into the stop level and losing track of what each setting represents.
The guide to modeling slippage and commission explains those settings in more detail. For a focused comparison, hold the stop rule and data fixed while changing the cost assumption, then inspect the affected trades as well as the summary. A fixed assumption cannot establish the actual cost of every historical gap.
How can you compare stop settings by hand?
A parameter is an input that changes how a strategy operates. To examine how a stop input interacts with gaps, begin with a saved version of the script and a written description of its exit rule, so the comparison has a clear starting point.
Keep the symbol, session, date range, position size and fill assumptions the same while changing the input under study, so the comparison does not also introduce changes in those other parts of the test at the same time. Run the test for a chosen value, record that value and inspect exits near session openings, then repeat for the other values in the planned comparison.
Note which trades were open across a gap and whether their protective orders were active. A parameter sweep is the process of testing a set of input values, not a way to observe actual execution or establish the price an order would have received outside the simulation.
TradingTune automates TradingView strategy optimization. Manual inspection remains useful because a ranking alone does not show why an individual gap-related exit occurred or whether the fill model matches the question being tested.
Avoid changing the stop input, session and cost assumptions together and assigning the difference to the stop, because the comparison would leave more than the stop input changed between the runs. If the input also changes position size or entry timing, record that effect: it can alter which positions are exposed to a gap even when the fill rule stays the same.
For the broader process, see how to run a parameter sweep by hand. The aim is to understand the simulated exits and the conditions under which they appear, not to select a setting from a single past event as though that event settled the question.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
What should you record when comparing runs?
Keep a short record for each run that identifies the script version, input values and data view, so you can tell which version and conditions belong to the results you are inspecting. Include the session, timeframe, testing period, order type and assumptions used for costs and fills, so a later comparison can distinguish a changed input from a changed test setup.
If you use more detailed historical bars, note that choice and any uncertainty about their coverage. For each gap-related example, record the position direction, prior close, following open, stop level in force and simulated exit, along with the order’s activation time if it can be established.
These details help reconstruct why a fill appeared away from the stop without relying on the summary alone, and they make it easier to trace the reported exit back to the conditions recorded for that run. Separate a missing fact from a negative finding: if the record does not establish when the stop became active, write that down rather than marking the trade as unaffected by the gap.
If another exit rule could have closed the position, note that competing explanation until the order history can be inspected, rather than treating the gap as the established cause of the exit while the relevant order details remain unclear. A run with no identified gap-related exits is not proof that the strategy has no gap exposure: it may have no position open across the relevant interval, or the chosen data and period may not show the case under review.
What can this check establish?
The check can show how a particular simulation handled a particular order under its recorded data and settings, making it possible to discuss that simulated fill in the context of the test that produced it. It can also reveal whether an exit sits beyond the intended stop and whether that difference is consistent with the documented gap rule, provided the order was active at the relevant time.
Those findings describe a historical model rather than a live fill. An opening price in a backtest is not a promise that an order would have filled there in full in a real market, where available prices, order handling and the amount available at those prices can matter.
A fixed slippage setting or a finer chart does not remove all of that uncertainty. Before interpreting a comparison, check that the script represents the intended stop, that the order existed before the gap and that the data covers the interval being discussed.
If any of those facts is unclear, keep the conclusion narrow and identify what could not be checked, so the account of the exit does not present an uncertain detail as something established by the test. The result is a better account of the model’s limits, not a reason to treat a stop distance as a fixed bound on an exit or a past simulated fill as a forecast of the next one.
Sources
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.