FAQ · Getting systematic research right

Should my backtest use market or limit orders?

Whichever you will use live, because they test different things. A market order always fills and pays the spread and slippage. A limit order saves that cost but fills only when price comes to it, and misses the trades that run away. A backtest of limit entries is honest only if a limit fills when price trades through it, and the trades it missed stay missed.

Whichever you will use live, because they test different things. A market order always fills and pays the spread and slippage. A limit order saves that cost but fills only when price comes to it, and misses the trades that run away. A backtest of limit entries is honest only if a limit fills when price trades through it, and the trades it missed stay missed.

What each order costs

MarketLimit
FillsAlways, at the next available priceOnly if price reaches the limit
PriceAsk to buy, bid to sell, plus slippageThe limit or better
Hidden costSpread and slippage on every tradeMissed trades, often the best ones

The hidden cost of limits is adverse selection: a buy limit below the market fills when price is falling toward it, and misses when price rises away. The fills you get are tilted toward trades that started badly.

Three ways limit backtests go wrong

  • Filling on a touch. A limit at exactly the bar's low is filled in many backtests. Live, there were other orders ahead of yours at that price, and a touch often does not fill. Require price to trade through the limit, at least by the spread.
  • Filling at the limit when price gapped through it. A buy limit at $95 when the stock opens at $88 fills near $88. See gaps and overnight fills.
  • Leaving the limit open forever. A day-old limit that fills a week later is a different trade. Give it an expiry.

Stops are market orders

A stop becomes a market order when price trades through it, so it pays the spread and slippage and can fill well beyond its price. Bracket take-profits are limits.

How Reamer Research handles it

In Reamer Research, a buy limit fills when the simulated ask reaches it, and a sell limit when the bid does, so with a spread set a limit has to be traded through, and a touch of the bar's low is not enough. tif='GTD' with an expiry cancels it if it does not fill in time. This object runs the same signal with either order type:

import reamer_research as rr

class PullbackEntry:
    def __init__(self, use_limit, offset=0.10, bars_alive=3, qty=10):
        self.use_limit, self.offset, self.bars_alive, self.qty = use_limit, offset, bars_alive, qty
        self.lookback = 25
    def on_bar(self, d):
        if d.close[0] == 0:
            return None
        trend = d.close[-1] > d.close.mean()
        if d.position() > 0 and not trend:
            return rr.close_position()
        if d.position() != 0 or not trend or d.open_orders():
            return None
        if not self.use_limit:
            return rr.buy_market(self.qty)
        expiry = int(d.ts) + self.bars_alive * 300                  # 5-minute bars
        return rr.buy_limit(d.close[-1] - self.offset, self.qty,
                            tif='GTD', expiry_timestamp=expiry)

costs = dict(spread=0.02, slippage=0.005)
for use_limit in (False, True):
    r = rr.backtest(PullbackEntry(use_limit), 'data/SPY_5min.bin', **costs)
    print('limit ' if use_limit else 'market', r.closed_trades_count, 'trades,',
          r.expired_orders, 'expired,', round(r.net_pnl, 2), 'net')

The report counts expired orders, so the trades the limit missed are visible beside the cost it saved. The visual trade diagnostics tool (open_viewer=True) draws resting orders from the order log, so each limit is shown where it waited and whether it filled. The same rule works as a function or a class with class attributes; the object form here lets one run compare both order types.

Limits to know

  • Queue position is modelled through the spread. The engine has no order book, so a limit fills once the bid or ask crosses it; with a zero spread that is a touch of the price. Set a realistic spread for limit strategies.
  • Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to compare order types on your own entries.

A $20 month includes the full kit, so you can test your own entries both ways and cancel if it does not fit.

Next questions

How realistic do slippage and spread need to be in a backtest?Realistic enough that the result survives them. Set spread, slippage and commission per instrument from what your broker actually charges, let spread and slippage widen when the market moves fast, and then rerun at one and a half and two times those costs. A strategy whose edge disappears under slightly higher costs was never a reliable edge.How should a backtest fill stops and limits across an overnight gap?At the opening price, or close to it, and not at the order's own price. When a stock opens below a sell stop, the stop triggers at the open and fills there, worse than the stop. When it opens below a buy limit, the limit fills at the open, better than the limit. A backtest that fills at the stop or limit price across a gap overstates stops and understates limits.How do I model my broker's commissions in a backtest?Copy your broker's actual schedule, per share, per contract or a percentage of value, with its minimum and maximum per order, and charge it on every fill, entries and exits both. For a strategy that trades small orders often, the minimum per order is usually what matters most, and a flat per-share rate without it understates the cost.How do I read a backtest report? Sharpe, Sortino, drawdown and profit factor explainedStart with the trade count and costs, then risk-adjusted return (Sharpe and Sortino), then the worst loss from a peak (maximum drawdown), then how wins compare with losses (profit factor and win rate). No single metric is enough; a strategy is only as good as its weakest honest figure.

Every answer here restates the documents that ship in the kit, which are authoritative. All questions.

Reamer Research

Your first backtest in a minute

Backtesting and live trading in Python and C++. Free to install in Evaluation Mode, with no key or sign-up.

pip install reamer-research

A licence at $20 a month removes every limit. The same code runs unchanged.

Reamer Server

The order-management core for your firm

Your venues, your risk rules on every order, one strategy per CPU core, on your own Linux servers.

$24,000 / year

Or start with a 30-day trial at $2,000.