MarketInOut Stock Screener Log In | Sign Up

Stop Loss, Take Profit and Trailing Stops in Backtests

By MarketInOut · November 15, 2026

Stops and targets often decide a strategy’s result more than its entry rule does. In a backtest they also behave in ways that aren’t obvious: when they become active, what happens on a gap, and which one wins when both are hit on the same day. Here’s how stop loss, take profit, trailing stops and time limits work in MarketInOut’s backtester, with examples.

Where to set them

On the strategy page, the Position Maintenance section has four exits. You can use any combination, together with a closing formula:

  • Stop loss: sells if the price falls a set distance below the entry price.
  • Take profit: sells if the price rises a set distance above the entry price.
  • Trailing stop loss: sells if the price falls a set distance below the highest high since entry.
  • Time limit: sells after a set number of bars, or at the end of each week, month, quarter, half-year or year.

Percent or ATR

Distances can be set in percent or in multiples of the 14-day Average True Range (ATR), a measure of how much the stock usually moves in a day.

In percent. You buy at $100 with a 15% stop loss, a 35% take profit and a 20% trailing stop:

  • The stop loss sits at $85 and the take profit at $135.
  • If the highest high since entry reaches $120, the trailing stop moves up to $96 (20% below $120).

In ATR. You buy at $160 when the ATR is $12, with a 2 ATR stop loss, a 5 ATR take profit and a 2 ATR trailing stop:

  • The stop loss sits at $136 ($160 − 2 × $12) and the take profit at $220 ($160 + 5 × $12).
  • If the highest high reaches $215, the trailing stop moves up to $191 ($215 − 2 × $12).

ATR-based stops adapt to each stock: a volatile stock gets a wider stop, a quiet one a tighter stop. Percent stops are simpler to reason about but treat a utility and a biotech the same way.

When stops become active

  • Stop loss and take profit are set from the entry price and apply from the next bar on.
  • The trailing stop is recalculated at each close from the highest high since entry, and the new level applies from the next bar. During the day it doesn’t move, even if the price makes a new high.
  • A trailing stop only moves up. If today’s calculation gives a lower level than the current one, the stop stays where it was.
  • Gaps: if a stock opens below its stop, the position closes at the opening price, not at the stop level. That’s what would happen in real trading too.

When stop and target are hit on the same day

On daily data the backtester sees each day’s open, high, low and close, but not the order in which they happened. If a day’s low touches the stop and its high touches the target, it can’t know which came first, so it assumes the worse: the stop. This makes results slightly pessimistic, which is the safer mistake to make.

Stops and targets are the only way a position can close in the middle of a bar. A closing formula is checked at the close.

Time limits and rebalancing

Close position after a number of bars suits short-term strategies where the edge, if any, lasts a few days. Close position at the end of a month, quarter or year empties the portfolio at that point, and new positions open from the next bar. That’s how to test a strategy that rebalances regularly, such as holding the ten strongest stocks each month.

Finding good settings with the optimizer

The optimizer tests a range of stop and target values in one go. Give it a start, a step and an end, such as 10 / 2 / 20, and it runs 10, 12, 14, 16, 18 and 20 side by side, in the strategy’s unit (percent or ATR).

Use it to see how sensitive the strategy is, not to find the single best number. If results change a lot between a 12% and a 14% stop, the strategy is fragile. If they are similar across the range, the exit rule is robust, and a value in the middle of that range is a reasonable choice.

Practical tips

  • Start with a closing formula or a time limit, then add stops and see whether they help or just cut winners short.
  • A stop closer than about one ATR is likely to be hit by ordinary daily noise.
  • Check a few trades on a chart to see where the stops sat and why each position closed.

More detail in the help pages: position maintenance. See also how the backtester simulates trades.




Disclaimer - Privacy Policy - Terms of Service - Cookies - FAQ - Affiliates - Blog