Matana Labs

Stop and target inside one bar

A bar that touches both your stop and your target cannot say which came first, so a bar-based backtest has to guess. Matana Labs never decides from the bar: the engine walks the seconds inside it, one price per second, and the level the price reaches first is the one that fills.

The problem with bars

A 5-minute bar keeps four prices: open, high, low and close. If the high is above your target and the low below your stop, the bar is consistent with both orders: target first, or stop first. Bar backtesters pick a rule (often “the stop first”, sometimes “whichever is nearer the open”) and apply it to every such bar. Our study Stop loss or take profit first? How often bars can't tell measures how often this happens and how much the guess changes results.

The bar aloneThe same bar, second by secondtargetstopwhich came first?second 15: target fills, position closedlater stop touch: no position leftIllustration, not market data: 60 one-second prices of one 1-minute bar.
Left, the bar: both levels inside its range. Right, the same bar by the second: the target is reached first, so the stop is never hit.

How the engine decides

At what price

A stop fills at the price of the second that reached it, not at the stop level: if the price stepped from above the stop to below it, the fill is the lower price. A target fills at the price of the second that reached it, at the level or better. A limit order fills at its level or better, when the second has volume left for it.

How much that matters, from our engine validation on QQQ: in “SMA cross with stop and target” every one of the 98 stop exits filled at the second’s price; filled at the stop level instead, the same trades would have shown $436.51 more net profit; in “RSI(2) mean reversion” every one of the 56 stop exits filled at the second’s price; filled at the stop level instead, the same trades would have shown $248.72 more net profit.

See it on your own trades

Open any trade of a backtest in Backtest Lab and play the day: the chart shows the seconds around the entry and the exit, with the stop and target lines. Analysis Lab compares the same strategy with fills on bars and fills by the second.

Updated 2026-11-24. Describes the product as it is today; numbers are read from the code when the site is built. Educational content, not financial advice.