Time-Gated Spread Trading with Position-Based Entry and Exit Algorithms
Summary
This example manages a spread position using configurable entry and exit prices, a maximum position, order pay-up, and an execution interval. On each spread update, it checks whether the current time falls within the configured trading window. Outside that window it stops both opening and closing algorithms; during the window it inspects the spread position and starts the corresponding actions.
When flat, it can launch long and short opening algorithms. With a long spread position, it stops opening activity and starts a short algorithm to close the position; with a short position, it starts a long cover algorithm. Position and algorithm status callbacks keep displayed state current and clear completed algorithm identifiers. The example supplies no signal for choosing prices, no backtest or performance evidence, and no explicit handling in its order and trade callbacks. Its behavior therefore illustrates order orchestration, not a validated spread edge or complete risk framework.
Key ideas
- Spread updates are acted on only within a configured daily time window.
- When flat, the strategy can launch both long and short opening algorithms.
- Existing long and short spread positions trigger opposite-side closing algorithms.
- Algorithm status callbacks clear identifiers when execution algorithms become inactive.
- The example does not define a pricing signal or provide performance and risk evidence.
Tags
From a private course collection; the original is not published.