Testing and analysis

Stop Loss and Take Profit in the Same Bar: Backtest Checks

Published ForeXpert team日本語で読む

When a stop loss and take profit fall inside the same bar, the bar's open, high, low and close cannot tell you which was reached first. Check when the orders became active, inspect finer data if available, and keep unresolved cases visible under both exit assumptions.

This guide explains how to handle those cases in manual backtesting without turning a candle's appearance into an invented price path. The aim is to establish consistent fill assumptions before judging the trading rules. A displayed win or loss is a simulation result; you still need to understand what information supports it.

Why a stop loss and take profit in the same bar are ambiguous

A candle summarizes four prices, usually called OHLC: the open, high, low and close. It does not contain the timestamps of the high and low or every movement between them. A bullish candle does not establish that the low came first, and a long upper wick does not establish that the high came first.

Consider this fictional example of the mechanics. You hold a long position from a previous bar, with a stop at 99 and a target at 102. The next bar opens at 100, reaches a high of 103 and a low of 98, and closes at 101.

Illustrative path inside the bar First exit level reached Simplified outcome
100 → 103 → 98 → 101 Target at 102 Target exit
100 → 98 → 103 → 101 Stop at 99 Stop exit

Both paths produce identical OHLC values. For this illustration, assume continuous prices, a complete fill at the specified level, and cancellation of the other exit after the first fill. These are deliberately simplified assumptions, not a reconstruction of real execution.

A backtesting engine needs a rule for missing intrabar information. TradingView's official broker emulator documentation, for example, describes assumptions about price movement within historical bars. An exit marker on a chart therefore need not mean the historical sequence was directly observed. This distinction matters when you compare tools or repeat a test with different data.

Check when the orders became active

Before asking which level was touched first, ask whether the relevant order existed when that touch happened. A bar's full high and low cannot automatically be used to evaluate an order created partway through it.

Suppose price reached the high early in the bar and your entry filled later. Even if that high exceeded your target, it does not prove that price returned to the target after entry. Counting a target exit from the full bar range would mix pre-entry and post-entry information.

Write down four details:

  • Whether the position existed before the bar opened or began during it.
  • When the stop and target became active.
  • When any order changes or cancellations took effect.
  • Which price series is used to evaluate the orders.

The last point includes whether the data represents bid, ask or midpoint prices and which price triggers the simulated order. A visible high or low alone is insufficient when the chart and execution model use different price conventions. Keep those conventions with your backtesting cost assumptions.

Treat gaps, partial fills and changes to exit orders as separate complications. Choosing a stop-first convention does not establish that a real stop would fill at its exact level. The two-path example assumes those complications away so that the sequencing problem is clear.

A three-step process for manual backtesting

Decide how you will handle unresolved bars before collecting results. Otherwise it is easy to choose a favorable interpretation after seeing whether the trade would improve the report. Keep execution research separate from the trading decision you originally recorded.

Three checks for ambiguous exits: establish when orders became active, inspect finer data, then record stop-first and target-first outcomes if the sequence remains unresolved
Diagram: How to handle a stop and target inside the same bar

1. Freeze the order timeline

Record the entry, stop and target levels together with their activation times. Do not move the exits after inspecting the completed candle. Preserve the original record and add an execution-review note beside it, so you can distinguish a data question from a change to the trading rules.

The same separation protects against look-ahead bias. Information discovered during an execution review must not become information that supposedly informed the earlier entry. If you replay the setup again, remember that you now know more about it than you did on the first pass.

2. Inspect finer data

Use lower-timeframe data from a compatible source, with aligned timestamps and the same price convention. If an early sub-bar reaches only the stop and a later sub-bar reaches the target, you may be able to establish the first touch for orders already active throughout that interval.

Finer bars do not solve every case. Both levels may still sit inside one minute bar, or the data needed for that date may be missing. Record the remaining uncertainty rather than guessing a route through the candle. More detailed data is useful only to the extent that it actually resolves the order timing.

3. Keep unresolved cases in separate calculations

Choose and document a baseline convention, such as stop-first, and retain a target-first comparison. In the simple fixed-exit model here, stop-first is the cautious assumption. It is not a statement about the actual historical path or a worst possible live loss.

Do not silently delete the affected trades. That can remove precisely the volatile conditions your rules need to handle. If a case must be excluded, disclose the count and reason, and show the results before and after exclusion. A report should make the missing information visible to whoever reads it next.

A worked example of sensitivity to exit assumptions

The following is a fictional arithmetic example, not trading performance. Assume ten independent trades of fixed size. Each has an intended loss of $100 at the stop and a gain of $200 at the target. Ignore fees, slippage, compounding and partial exits. Changing one exit does not change whether later trades occur.

Eight trades have a known sequence: three reach the target first and five reach the stop first. Their combined result is 3 × $200 − 5 × $100 = $100. The remaining two trades have both exit levels inside a bar and cannot be resolved from the available data.

Assumption for the two unresolved trades Result from those trades Result across all ten
Both stop-first −$200 −$100
Both target-first +$400 +$500

The difference is 2 × ($200 + $100) = $600. Averaging the totals and calling $200 the true profit has no justification: the OHLC observations do not tell us the relative likelihood of the two outcomes.

Here the assumption changes the sign of the aggregate result. That is a reason to improve the execution evidence before drawing a conclusion about the rules. It is not evidence that either endpoint is achievable, nor is the interval a statistical confidence interval.

In a more complex test, an earlier exit may allow a later entry, change exposure or alter position size. You would then rerun the full sequence under each convention instead of adjusting the final total by hand. The arithmetic above works because the trades and their sizes are held fixed.

Backtest results do not guarantee future performance. Live trading carries a risk of loss, and this comparison is not a forecast range for future returns.

What to record, and how to practice with ForeXpert

A useful record lets you revisit the reason for an outcome. You can maintain the extra execution notes in a notebook or spreadsheet when your practice tool does not have dedicated fields.

Field What to record
Bar identity Pair, timeframe, date, time and timezone
Order state Entry time and each exit order's level and activation time
Evidence Data source, price convention and finer data inspected
Classification Resolved or unresolved, with a reason
Reporting Baseline assumption, comparison assumption and any exclusion

ForeXpert lets you step through historical charts one bar at a time, place market, limit and stop orders, and set a stop loss and take profit. You can display multiple timeframes together, and every currency pair and historical period is available on the free plan.

ForeXpert estimates the path inside each bar from its direction: a bullish bar is treated as open → low → high → close, and a bearish bar as open → high → low → close. When one bar reaches both your stop loss and take profit, the order reached first on that path closes the trade. This is one fixed assumption, not the actual sequence of prices. The unresolved-case labels and paired calculations described here are a way to check, in your own notes, whether that assumption is driving your conclusions.

For a practical review session, select a completed trade whose exit depends on the intrabar sequence. Preserve the original result, write down what data you checked, and state exactly what remains unknown. Repeat that process consistently rather than spending effort only on trades that would improve the total. The number of unresolved trades is useful context even when you cannot resolve them all.

Summary

When both exit levels lie inside a candle, start with the order timeline rather than the candle's shape. Inspect finer data, keep unresolved cases visible, and compare the result under clearly stated assumptions.

Add one sentence to your testing plan that defines how unresolved bars will be counted. Then report their number beside the two calculations, so you can see whether an execution assumption is driving the conclusion.