|
When several entry orders are triggered within the same bar, the data cannot say which was filled first: a bar records only its open, high, low and close. This topic describes the order the backtest engine uses, and where that order affects results.
Selection Comes First
Setups are selected, and capacity constraints such as MaxPositions applied, before any fills are known (see Backtest Loop Overview). A setup selected with a limit or stop order counts against the constraints whether or not its order fills, so the order of fills within the bar does not affect which setups are selected.
In the Intraday phase, entries are processed before exits, so a limit or stop exit never frees capital or a position slot for a limit or stop entry in the same bar.
Entry Order Within a Bar
Once selection is complete, the selected setups of each strategy are entered one at a time, in descending EntryScore order. Setups with equal EntryScore values, which includes all setups of a strategy that has no EntryScore, are entered in alphabetical order of symbol.
Strategies are processed in the order they appear in the script: all entries of the first strategy, then those of the next. When MaxEntries is set in a Combined or StatsGroups section, the strategies instead take turns, one entry each.
Where the Order Matters
The order matters when an entry can still be refused at fill time. The main case is MaxEntries, which caps the number of entries per bar and counts them in the order above: when more orders are triggered than the cap allows, those with the highest EntryScore are filled and the rest are skipped (with the reason shown in the trade list when skipped trades are included).
Weekly and Larger Strategies
In a Weekly or larger strategy, each fill is dated at the daily bar on which its price was crossed (see Limit and Stop Fills Within a Bar). Entries are still processed in the order above, not in the order of those fill dates.
|