MarketInOut Stock Screener Log In | Sign Up

How the Backtester Simulates Trades: Fills, Portfolio Size and Position Sizing

By MarketInOut · November 15, 2026

Two backtests of the same idea can give very different results depending on a few settings: when orders fill, how many positions you hold, which stocks get bought first and how big each position is. This guide explains how MarketInOut’s backtester makes those decisions, so you can set them on purpose and trust what the results tell you. If you haven’t set up a strategy yet, start with how to backtest a stock screening strategy.

The daily loop

The backtester steps through history one bar at a time, usually one trading day. At the close of each bar it:

  1. closes the open positions that meet the closing formula, a stop or a time limit;
  2. runs the entry formula as a screen on that day’s data;
  3. buys matching stocks into the free slots of the portfolio, and ignores the rest.

Signals use closing prices only. The backtester works with each bar’s open, high, low, close and volume, and doesn’t know the order of price moves within a bar. A slot freed during a bar can be filled only at that bar’s close.

When orders fill: the testing model

The entry model decides the price you get once a stock matches:

  • Close prices: you buy at the close of the day the stock matched. Simple, and the default for most tests.
  • Next bar open: you buy at the next day’s open, which is closer to what you could actually do after seeing the signal in the evening.
  • Next bar if: you buy the next day only if the price moves the way you want, for example 2% above the previous high, or on a gap up. This is the only model that opens a position in the middle of a bar.

Exits work the same way, with Close prices or Next bar open. Within a bar, a position can close only by its stop loss, trailing stop or take profit.

Two related settings control timing further. Limit Market Entry to End of Day, Week or Month checks the entry rule only on the last bar of that period, for example only at Friday’s close. Close position at the end of a week, month, quarter, half-year or year closes everything at that point, which turns a strategy into a regular rebalance.

Hourly and other intraday bars

If your formulas use intraday bars, such as hourly ones, the backtester works the same way on those bars: one bar is one hour instead of one day, and moves within the hour are not seen. The working timeframe is the shortest one used in the opening and closing formulas, and settings counted in bars refer to it.

Portfolio size and which stocks get bought first

The portfolio holds a fixed number of positions, set by Portfolio max size. Many traders use 20 to 30 to spread risk. When more stocks match than there are free slots, the backtester picks them in priority order:

  • Prioritize Stocks by on the strategy page, for example the highest average volume first; or
  • sortby() in the entry formula, for example the most oversold first:
index(sp500) and rsi(2) < 10 and price > sma(200) and sortby(rsi(2), asc)

If neither is set, stocks are taken in the order they’re stored in our database, which is roughly alphabetical. A strategy that keeps buying stocks starting with A is testing the alphabet, not your idea, so always set a priority.

The backtester holds at most one position per stock. It doesn’t add to a position or sell part of it; to approximate scaling out, split the strategy in two with different exits.

Position size

Risk per trade can be a fixed amount or a percentage of capital.

Fixed amount. The backtester buys as many whole shares as fit. With $2,000 per trade and a $95 stock, it buys 21 shares for $1,995.

Percentage of capital. Here two rules apply: the number of positions can’t exceed 100% divided by the percentage, and no new position can exceed that percentage of capital. Open positions count at their purchase price, not today’s value. For example, with $100,000 and 10% per trade:

  1. Ten stocks match, and the backtester opens ten positions of about $10,000.
  2. Two of them gain 50% and close at their target. The account now holds $30,000 in cash and eight positions counted at $80,000, $110,000 in total.
  3. Two new stocks match. Each gets $11,000, 10% of $110,000. Two positions of $15,000 would each risk about 13.6% of capital, more than the 10% limit.
  4. If those two then fall 50% and hit their stops, cash drops to $10,000. The next two positions get $5,000 each: free cash is shared equally, even when they open on different days.

Costs

Commission is charged on both the buy and the sell, and the bid-ask spread on the sell. With a 0.01% commission, a 0.1% spread, 100 shares bought at $70 and sold at $100, the profit is $2,988.30 instead of $3,000. On one trade that’s small; on a strategy that trades every few days, costs can decide whether it makes money at all.

Settings worth checking before you trust a result

  • A priority is set, so the stocks bought aren’t chosen by name.
  • The entry model matches how you would really trade: Next bar open if you act on signals the next morning.
  • Commission and spread are realistic for your broker.
  • The portfolio size and risk per trade add up: 10% per trade means up to 10 positions.

More detail in the help pages: how the backtester works and testing models.




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