RealTest User Guide
RealTest User Guide

 

 

Navigation: Backtest Engine Details >

Limit and Stop Fills Within a Bar

 

 

 

 

An entry or exit with a limit or stop price is filled within a bar, at its price, when the bar trades through it, or at the open if the bar opens beyond it. For a Daily strategy, RealTest has only each bar's open, high, low and close to go on. For a Weekly or larger strategy, it finds the fill by walking the daily bars within each strategy bar (see Weekly and Larger Strategies, below).

Fills From the Bar Alone

Modeling stop and limit fills from a bar's prices alone loses a little fidelity, but comparisons of model and live results for short-term daily strategies show that the per-trade differences largely cancel out over a large sample of trades. Orders at the open or the close are modeled exactly, and orders at the close are practical to trade: they can be submitted a minute or two before the close and filled within seconds, except in very thin stocks or very large size.

Stop and limit fills can be simulated accurately from the bar alone, provided that the engine handles the following, as RealTest does:

1.If the open gaps beyond the price trigger, model the fill at the open (plus slippage), not the trigger price.

2.If the strategy includes both limit or stop entries and limit or stop exits, and the bar implies that more than one of the price triggers was hit (within that bar’s range), then the model must handle each of the following potential scenarios correctly:

a.Limit order entry and stop order exit (loss):  it can be assumed that the entry preceded the exit, and both can be filled.

b.Limit order entry and limit order exit (target): it can NOT be assumed that the entry preceded the exit, so the target is not hit in the model (unless Ambiguity: Target is specified).

c.Stop order entry and limit order exit (target): it CAN be assumed that the entry preceded the exit, so the target is therefore filled.

d.Stop order entry and stop order exit (loss): it can NOT be assumed that the entry preceded the exit, so the stop is therefore not hit in the model (unless Ambiguity: Stop is specified).

3.One exception to all cases of (2) is if the stock gaps beyond the entry trigger (1), in which case the entry was at the open so the exit trigger is non-ambiguous.

4.In RealTest's "Default" Ambiguity mode, which is the default setting and is not quite as strict as "Neither", it is assumed that:

a. if Close > Open, then Low happened before High

b. if Close < Open, then High happened before Low

This allows a best-guess assumption to be made in all cases. A pure doji bar (Close = Open) is resolved as in Stop mode.

These rules apply to every bar of a Daily strategy, and to a single daily bar of a Weekly or larger strategy when both prices fall within it.

Weekly and Larger Strategies

When a strategy's bar size is Weekly or larger, limit and stop fills are found by walking the daily bars within each strategy bar. The trade list records the date of the daily bar on which the price was crossed, and the fill is priced on that bar (at its open if it opened beyond the price).

The same walk settles the order of events within a strategy bar: whether the stop or the profit target was hit first, and whether a stop touched on the entry day came before or after the entry. The Ambiguity setting is consulted only when both prices were touched within a single daily bar.

By default a limit or stop order lives for one bar of the strategy's bar size, and is placed again on the next bar if the formulas still call for it.

 

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC