|
|
|
Log In | Sign Up | ||
How the Backtester Simulates Trades: Fills, Portfolio Size and Position SizingTwo 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 loopThe backtester steps through history one bar at a time, usually one trading day. At the close of each bar it:
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 modelThe entry model decides the price you get once a stock matches:
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 barsIf 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 firstThe 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:
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 sizeRisk 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:
CostsCommission 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
More detail in the help pages: how the backtester works and testing models. |
Disclaimer - Privacy Policy - Terms of Service - Cookies - FAQ - Affiliates - Blog |