|
Category
Strategy Elements
Description
Assigns a strategy or benchmark to an entry setup processing phase; lower-numbered phases finalize their orders first
Input
A constant expression (a number or a Parameter); the minimum phase is 1
Notes
Each bar, entry setups are collected and finalized (ranked, capped, order flags set) in ascending EntryPhase order, and entries fill only after the last phase. No fills or equity effects are visible from one phase to the next, but final order flags and capacity reservations are.
A section in a later phase therefore sees the final order state of every earlier phase — Extern(@strategy, IsOrder), OrderSum, IsSetup — in both EntrySetup and SetupSkip formulas. This makes same-bar de-confliction between strategies deterministic. For example, to keep a short strategy out of any symbol that the long strategy is entering or already holds:
Strategy: longs
EntryPhase: 1
// long entry rules
Strategy: shorts
EntryPhase: 2
SetupSkip: Extern(@longs, Shares > 0 or IsOrder)
// short entry rules
Sections that share a phase are finalized together, turn by turn, as described in Backtest Loop Overview: declaration order or StrategyScore decides which strategy picks first at each turn, and MaxPerTurn how many setups it can add per turn. Within a shared phase, another section's same-bar order state is only partially visible: orders granted in earlier turns of the same bar can be seen, but later ones cannot. Use distinct phases whenever complete visibility is needed.
Phase numbers need not be consecutive — only their relative order matters. EntryPhase can be inherited from a Template via Using. It is not valid in a StatsGroup or Combined section.
Defaults when EntryPhase is not specified: each Benchmark gets its own phase, in declaration order, before every explicitly numbered phase, and Strategy sections without an EntryPhase share a single phase after the highest explicit value. This preserves the long-standing default behavior: all benchmarks finalize their orders before any strategy processes its setups.
A benchmark (or strategy) can also be given a later phase than other strategies, so that it reacts to their final orders — something the default ordering never allowed.
Phases order setup processing within an entry time. They do not reorder the time-of-day phases of the daily loop — for example, a ThisClose section cannot be made to precede a section that enters at the open.
Order generation (Orders mode) processes setups in the same phase sequence, so generated orders always match what the backtest would have done on that date.
EntryPhase was introduced in version 2.0.32.4. In earlier versions, the default ordering described above (benchmarks first, in declaration order, then all strategies together) was the only behavior.
See Also: SetupSkip, IsOrder and Backtest Loop Overview
|