|
Category
Strategy Elements
Description
Specifies when a strategy enters new positions
Choices
ThisClose - entries occur at the close of the current day
Intraday - entries occur when a trigger price is first touched tomorrow (default for limit and/or stop orders)
NextOpen - entries occur at tomorrow's open (default for market orders)
NextClose - entries occur at tomorrow's close
formula - a string formula that chooses NextOpen, Intraday or NextClose for each setup -- see Dynamic entry time below
Notes
Using ThisClose implies an ability to generate realtime trading signals using live data. RealTest will not be able to generate Tomorrow's Orders for ThisClose entries.
For strategies with no EntryLimit or EntryStop, EntryTime controls the time at which a market order is generated. NextOpen implies that a standard MKT order is placed before the open, to be filled at the open. (Intraday is interpreted as NextOpen for market orders.) NextClose implies that a MOC order is placed before the open, to be filled at the close.
EntryTime also applies to strategies that use an EntryLimit and/or EntryStop price.
Using ThisClose entry with EntryLimit specified is equivalent to adding "and C < n" to EntrySetup (for a long-side strategy) where "n" is the EntryLimit price. Similarly, a long EntryStop would be equivalent to "and C > n". Reverse these comparison operator directions for short-side strategies. As previously stated, orders cannot be generated in advance for this mode.
With Intraday, NextOpen, or NextClose limit or stop entries, the trigger price is calculated using the prior bar, and the order can be placed in advance.
An Intraday EntryLimit or EntryStop is a standard LMT DAY or STP DAY order.
A NextOpen EntryLimit is a LMT OPG order, and a NextOpen EntryStop is STP GTD 9:31 EST.
A NextClose EntryLimit is a LOC order, and a NextClose EntryStop is STP GAT 15:58 EST.
In all of the above, if both EntryLimit and EntryStop are specified, the order becomes STP LMT with the same qualifiers.
(All of the above order types are stated using Interactive Brokers order nomenclature, and can be automatically generated by adding OrdersTemplate: Examples\ib_basket_trader.csv to your Settings and running your script in Orders mode.)
Dynamic entry time
Instead of one of the choices above, EntryTime can be a formula that returns one of the strings "NextOpen", "Intraday" or "NextClose", for example to enter less liquid symbols at the close and the rest at the open:
EntryTime: iif(InList("Illiquid"), "NextClose", "NextOpen")
The formula is evaluated for each setup on the same bar as EntrySetup, so the choice is already known when Tomorrow's Orders are generated, and each order gets the type described above for its time (e.g. MOC for a NextClose market entry). Setups with different entry times are ranked together and share MaxPositions and the other entry limits exactly as they would in a strategy with a single entry time -- only the fill time and order type differ.
The names must be quoted: an unquoted NextOpen inside a formula is the next bar's open price. Any other result stops the run with an error, and a result that cannot be calculated (NaN) uses the default time (NextOpen, or Intraday with an EntryLimit or EntryStop). ThisClose cannot be chosen by a formula, since it is decided a bar later and cannot be ordered in advance -- use a separate strategy for ThisClose entries. A strategy specifies either a time name or a formula, not both, and a formula cannot be used with DynamicSizing.
When exits can also be NextClose (see ExitTime) and the strategy has no ExitLimit or ExitStop, a NextClose exit is decided at the open so that the same day's entries can reuse its position slot and capital, as in a strategy that both enters and exits at NextClose. With mixed entry times this also lets a NextOpen entry use capital that a real account only gets back at that day's close.
For more information on how the backtest engine works in general, see Backtest Engine Details.
|