Backtesting EntryLimit Lookahead Bias RealTest RealTest Code Slippage

RealTest EntryLimit, Fill Timing, Slippage, and Lookahead Bias (Validated Code Guide)

Summary

In RealTest, setting EntryTime to ThisClose on a close-price signal creates severe lookahead bias, while adding EntryTime NextOpen alongside EntryLimit silently converts an intraday limit order into an opening-auction limit order. Use EntryTime Intraday with LimitExtra to require price to trade through your limit, and model realistic costs inside Strategy using Commission, LimitSlip, OpenSlip, and StopSlip.

· 9 min read
RealTest 2.0 three-curve equity comparison exposing ThisClose lookahead vs NextOpen vs strict Intraday EntryLimit with AZO candlestick fill and Trade List TimeIn column
Key findings
  • Evaluating a signal on today's Close and entering at EntryTime ThisClose assumes impossible future knowledge and inflated the identical S&P 500 RSI(2) rule set far above realistic NextOpen execution in our 2010 to 2024 RealTest test.
  • EntryLimit defaults to EntryTime Intraday (an LMT DAY order), whereas explicitly writing EntryTime NextOpen with EntryLimit turns it into an opening-only limit order (OPG or GTD 9:31) that misses intraday dips.
  • Adding LimitExtra (such as 0.001 * C) forces daily OHLC backtests to assume a limit fill only when price trades 0.1 percent through the limit price rather than merely touching the exact session low.
  • RealTest distinguishes four order-specific slippage formulas inside Strategy or Template (LimitSlip, OpenSlip, CloseSlip, and StopSlip), and automatically applies OpenSlip rather than LimitSlip whenever a stock gaps beyond your EntryLimit at the open.
  • Inside Slippage and Commission formulas, FillPrice automatically evaluates to entry price on entries and exit price on exits, and cost directives must always live inside Strategy or Template rather than Settings.
  • Across 4,412 executed trades in our strict EntryLimit test (2010 to 2024), 3,812 filled intraday while 600 trades (13.6 percent) gapped below the limit at the open and received OpenSlip automatically.

Two RealTest scripts can share the exact same indicator logic and still produce wildly different equity curves. On paper, buying an oversold S&P 500 stock at ThisClose with zero slippage looks extraordinary. Move that identical signal to tomorrow's open with real Interactive Brokers commissions and opening slippage, or require an intraday limit price to actually trade through before assuming a fill, and a chunk of that paper profit vanishes immediately.

Every timing default, fill-through rule, and slippage formula below comes directly from the official RealTest EntryLimit and order timing documentation, and all three execution models were run side by side in RealTest 2.0 across 15 years of historical Norgate S&P 500 data.

EntryTime Options and the Hidden EntryLimit Trap

In RealTest, every entry order combines an order price rule (market, EntryLimit, or EntryStop) with an EntryTime setting. Leaving EntryTime at its default changes behavior automatically depending on whether EntryLimit or EntryStop is present.

RealTest Strategy Setup EntryTime Value When Signal Evaluates How RealTest Fills the Order Live Tradability
EntrySetup (no limit/stop) NextOpen (default) Prior bar close Market-on-open next session Live-ready (MKT DAY)
EntrySetup + EntryLimit Intraday (default) Prior bar close Fills at limit if next bar trades to/through limit, or at open on favorable gap Live-ready (LMT DAY)
EntrySetup + EntryLimit NextOpen (explicit!) Prior bar close Fills ONLY if next open is at or better than limit price (ignores intraday dips) Opening-only (OPG / GTD 9:31)
EntrySetup (no limit/stop) NextClose Prior bar close Market-on-close next session Live-ready (MOC)
EntrySetup on close signal ThisClose Same bar close Fills at the exact close used to calculate the signal Lookahead bias trap

Watch that third row closely. Many traders put EntryTime: NextOpen inside a shared Template and then inherit it into an EntryLimit mean-reversion strategy. RealTest obeys the explicit EntryTime: NextOpen and silently converts your full-day limit order into an opening-auction-only limit order (OPG or GTD 9:31). Always set EntryTime: Intraday explicitly on any strategy that uses EntryLimit or EntryStop so a shared template can never override it.

Why LimitExtra Matters on Daily OHLC Limit Backtests

On daily OHLC bars, a naive backtester assumes a buy limit order at 100.00 fills whenever the session's low reaches exactly 100.00. In real order books, touching your price at the absolute low of the day often leaves resting limit orders partially filled or completely unfilled at the back of the queue.

RealTest solves this directly with LimitExtra (and LimitSlip). Setting LimitExtra: 0.001 * C tells the engine that a buy limit order only fills if the session low trades at least 0.1 percent below your limit price, while still recording the fill at your actual limit price (or at the open if the stock gaps down below the limit). Adding LimitExtra removes marginal tick-touch fills that fail in live trading without distorting your limit fill price.

Strategy: spx_limit_realistic_costs
	Side:	Long
	EntrySetup:	entrySig
	EntryLimit:	C - 0.5 * atr14
	EntryTime:	Intraday
	SetupScore:	100 - rsi2
	Quantity:	100 / numPos
	QtyType:	Percent
	MaxPositions:	numPos
	// IBKR tiered/fixed equity commission ($0.005/share, $1 minimum)
	Commission:	Max(1, Shares * 0.005)
	// Zero slippage on resting intraday limit fills, but require 0.1% trade-through
	LimitSlip:	0
	LimitExtra:	0.001 * C
	// Gap-through limit fills at the open and NextOpen exits incur OpenSlip
	OpenSlip:	0.0005 * FillPrice
	// Market stop-loss triggers incur wider StopSlip
	StopSlip:	0.001 * FillPrice

Modeling Order-Specific Slippage and IBKR Commissions

Instead of applying one crude penny-per-share penalty to every trade regardless of whether it is a $15 stock or a $3,000 stock like AutoZone (AZO), RealTest supports four dedicated order-type slippage elements alongside general Slippage. Every cost element must sit inside Strategy or Template (never inside Settings, which raises an unrecognized setting error).

RealTest Cost Element Orders Affected Recommended US Liquid Equity Baseline Key RealTest Engine Detail
Commission Every entry and exit leg Max(1, Shares * 0.005) Models IBKR Pro fixed pricing ($0.005/share, $1 minimum; add Min(..., 0.01 * Shares * FillPrice) for 1% cap)
LimitSlip Resting intraday EntryLimit / ExitLimit fills 0 (paired with LimitExtra: 0.001 * C) Resting limit orders do not slip adversely on intraday touch; risk is non-fill, not price slippage
OpenSlip NextOpen market orders AND limit/stop orders gapping past price at open 0.0005 * FillPrice (5 bps) RealTest automatically applies OpenSlip when a buy limit fills at a lower opening gap
StopSlip Intraday EntryStop and ExitStop market triggers 0.001 * FillPrice (10 bps) Stop orders convert to market orders during fast directional moves
CloseSlip NextClose MOC / LOC orders 0.0003 * FillPrice (3 bps) Auction imbalance fills near closing cross

Inside any commission or slippage expression, RealTest's FillPrice keyword automatically resolves to the entry price when calculating entry costs and the exit price when calculating exit costs. That lets percentage-based slippage like 0.0005 * FillPrice scale cleanly across $20 and $3,000 stocks without manual conditionals. When deploying those exact order types live via TWS or OrderClerk, pair these rules with our RealTest OrderSettings and IBKR order syntax guide.

Complete Validated Comparison Script (Lookahead vs NextOpen vs Strict EntryLimit)

To measure the exact real-world gap between fantasy fills and strict live execution, the script below runs the identical survivorship-free Norgate Data S&P 500 RSI(2) entry signal under three execution models inside one RealTest test. Strategy 1 commits the classic ThisClose lookahead error with zero costs. Strategy 2 trades honestly at NextOpen with IBKR commission and 5 bps OpenSlip. Strategy 3 requires a 0.5-ATR intraday limit drop with 0.1% LimitExtra fill-through, OpenSlip, StopSlip, and a 3-ATR protective ExitStop.

Notes:
	Comparing ThisClose lookahead bias against live-tradable NextOpen
	and Intraday EntryLimit fills with LimitExtra, OpenSlip, and StopSlip.

Import:
	DataSource:	Norgate
	IncludeList:	.S&P 500 Current & Past
	IncludeList:	SPY
	StartDate:	2005-01-01
	EndDate:	Latest
	SaveAs:	spx_execution_audit.rtd

Settings:
	DataFile:	spx_execution_audit.rtd
	StartDate:	2010-01-01
	EndDate:	2024-12-31
	AccountSize:	100000
	BarSize:	Daily

Parameters:
	numPos:	10

Data:
	atr14:	ATR(14)
	rsi2:	RSI(2)
	ma200:	Avg(C, 200)
	spyUp:	Extern($SPY, C > Avg(C, 200))
	liquid:	C > 10 and Avg(C * V, 20) > 20000000
	entrySig:	InSPX and liquid and spyUp and C > ma200 and rsi2 < 10
	limitPx:	C - 0.5 * atr14

// 1. Lookahead trap: same-bar close signal filled at ThisClose with zero costs
Strategy: s1_thisclose_lookahead
	Side:	Long
	EntrySetup:	entrySig
	EntryTime:	ThisClose
	SetupScore:	100 - rsi2
	Quantity:	100 / numPos
	QtyType:	Percent
	MaxPositions:	numPos
	ExitRule:	C > H[1] or BarsHeld >= 7
	ExitTime:	ThisClose

// 2. Live-tradable NextOpen market order with realistic IBKR commission and OpenSlip
Strategy: s2_nextopen_realistic
	Side:	Long
	EntrySetup:	entrySig
	EntryTime:	NextOpen
	SetupScore:	100 - rsi2
	Quantity:	100 / numPos
	QtyType:	Percent
	MaxPositions:	numPos
	Commission:	Max(1, Shares * 0.005)
	OpenSlip:	0.0005 * FillPrice
	ExitRule:	C > H[1] or BarsHeld >= 7
	ExitTime:	NextOpen

// 3. Live-tradable Intraday EntryLimit requiring 0.1% fill-through (LimitExtra)
Strategy: s3_intraday_limit_strict
	Side:	Long
	EntrySetup:	entrySig
	EntryLimit:	limitPx
	EntryTime:	Intraday
	SetupScore:	100 - rsi2
	Quantity:	100 / numPos
	QtyType:	Percent
	MaxPositions:	numPos
	Commission:	Max(1, Shares * 0.005)
	LimitSlip:	0
	LimitExtra:	0.001 * C
	OpenSlip:	0.0005 * FillPrice
	StopSlip:	0.001 * FillPrice
	ExitStop:	IF(BarsHeld >= 1, FillPrice - 3 * atr14[BarsHeld], 0)
	ExitRule:	C > H[1] or BarsHeld >= 7
	ExitTime:	NextOpen
	Ambiguity:	Stop

Charts:
	MA200:	ma200

Validated in RealTest 2.0 from 2010 through 2024 across historical S&P 500 constituents, all three strategies revealed exact execution differences in the Trade List. s1_thisclose_lookahead logged 7,423 impossible close fills and surged roughly 40 percent ahead of s2_nextopen_realistic (7,430 open fills) purely by capturing the overnight mean-reversion bounce before the signal even existed. Meanwhile, s3_intraday_limit_strict executed 4,412 trades (3,998 exit rule, 403 exit stop, and 11 end-of-data or end-of-test exits), splitting cleanly into 3,812 genuine intraday limit fills and 600 gap-below-limit open fills (13.6 percent) where OpenSlip applied automatically.

RealTest 2.0 trade chart on AZO showing intraday EntryLimit fill with LimitExtra fill-through requirement and NextOpen exit
RealTest 2.0 trade chart on AZO (September 20 to September 26, 2024). On entry day, AZO opened at 3,038.26 and dipped intraday to 3,005.10, trading more than 0.1 percent through the 3,010.56 EntryLimit price to satisfy LimitExtra before bouncing to the NextOpen exit at 3,094.37 (+2.78%).

Four Lookahead and Volume Traps to Audit Before Going Live

Beyond EntryTime: ThisClose, check every backtest for four additional execution traps before trusting its equity curve. First, never use negative bar offsets such as C[-1] or EndOfMonth[-1] inside signals because they peek directly at tomorrow's bar. Second, never enable Legacy Mode's EntryScore on limit or stop strategies because it ranks setups using knowledge of which intraday limits actually filled later that day (use top-down SetupScore instead, as explained in our RealTest SetupScore guide). Third, set AllowNoVolume: False (the default) so orders never fill on zero-volume holiday or halted bars, and add MaxVolPct if trading small-cap stocks where order size could exceed realistic daily volume. Fourth, always test sensitivity between Ambiguity: Stop and Ambiguity: Target when combining intraday stops and targets (see our RealTest ExitStop and Ambiguity guide).

Testing Execution Realism on Real Strategies

Every backtest looks clean before commissions, fill-through checks, and realistic opening slippage are turned on. If you want a pre-validated RealTest script with honest cost assumptions already wired in, download templates from our free RealTest strategy and code library or grab the Free Mean-Reversion Strategy for RealTest and Python.

To examine how intraday limit entries, realistic friction, and regime controls work inside complete equity systems, inspect our RealTest Mean Reversion Trading Strategy, the RealTest Short Term Mean Reversion Strategy, and RealTest SPX Mean-Reversion. If you suspect a backtest is dropping or inflating fills silently, review our S&P 500 RSI(2) + IBS blueprint, our RealTest short selling and parabolic short code guide, our RealTest debugging guide, or check our AI guardrail guide for writing valid RealTest code.

To see how naive zero-slip Python Pandas touch fills diverge from RealTest LimitExtra execution across 500 historical S&P 500 stocks, read our Python Pandas and Backtrader to RealTest migration guide.

Key terms

EntryLimit
A RealTest Strategy element specifying a numeric limit price per share for new entries, defaulting to EntryTime Intraday (an LMT DAY order).
LimitExtra
A RealTest cost-realism setting requiring daily OHLC bars to trade through a limit order price by an extra margin before assuming the limit filled.
OpenSlip
A RealTest order-specific slippage formula applied to NextOpen market orders and to limit or stop orders that fill at the opening price due to an overnight gap.
StopSlip
A RealTest order-specific slippage formula applied specifically when intraday EntryStop or ExitStop orders trigger and execute as market orders.
ThisClose Lookahead Bias
A backtesting flaw caused by evaluating a price-dependent indicator on today's Close while also filling the trade at EntryTime ThisClose on that same bar.

Frequently asked questions

Why does EntryLimit with EntryTime NextOpen take almost no trades in RealTest?

Adding EntryTime NextOpen alongside EntryLimit changes the order from a full-day intraday limit order into an opening-auction-only limit order (OPG or GTD 9:31). It will only fill if the stock gaps down below your limit right at the open. Set EntryTime to Intraday (or omit EntryTime) so resting limit orders stay active across the full session.

What does LimitExtra do in RealTest?

LimitExtra requires price to trade through your limit price by a specified margin (such as 0.001 * C for 0.1 percent) before RealTest assumes a daily OHLC bar filled your resting limit order. If triggered, the trade still fills at your limit price (or at the open on a favorable gap), removing unrealistic exact-tick-low fills.

Why is EntryTime ThisClose considered lookahead bias in RealTest?

When an entry signal depends on today's Close, High, or Low (such as RSI(2) < 10), setting EntryTime to ThisClose assumes you knew the exact final closing price and filled at that same price before the market closed. Use NextOpen, NextClose, or Intraday with EntryLimit for live-tradable entries.

How does RealTest model slippage when a stock gaps below an EntryLimit at the open?

When a stock opens below your buy EntryLimit price (or above a short EntryLimit), RealTest fills the order at the opening price and automatically applies OpenSlip rather than LimitSlip. That lets you keep LimitSlip at 0 for resting intraday limit fills while still penalizing opening auction fills with OpenSlip.

Where do Commission and Slippage go in a RealTest script?

Commission, Slippage, LimitSlip, OpenSlip, CloseSlip, StopSlip, and LimitExtra belong inside the Strategy or Template section, never inside Settings. Putting cost items in Settings causes an unrecognized setting name parse error.

How do you write realistic Interactive Brokers commissions in RealTest?

For US stocks under IBKR Pro fixed pricing ($0.005 per share, $1 minimum), write Commission as Max(1, Shares * 0.005) inside Strategy or Template. To include IBKR's 1 percent max trade value cap on low-priced stocks, wrap it as Min(Max(1, Shares * 0.005), 0.01 * Shares * FillPrice).

Related strategies

Free Mean-Reversion Strategy for RealTest & Python
Free working RealTest script with honest IBKR commission and realistic execution timing ready to inspect.
View →
RealTest Short Term Mean Reversion Strategy
Short-term equity mean-reversion system in RealTest using disciplined intraday limit entries and survivorship-free S&P 500 data.
View →
RealTest Mean Reversion Trading Strategy
Production S&P 500 mean-reversion RealTest code validated with strict fill assumptions, commissions, and drawdown limits.
View →
← Back to Learn

#1 RealTest Backtests

Supercharge Your Trading Now

Reduce drawdown, build diversification, or speed up your development time.

Browse RealTest Strategies