Target Position Execution and Strategy Callbacks
Summary
This document describes a framework for building trading strategies around market-data and order-event callbacks. A strategy can receive tick, bar, trade, order, and stop-order updates; load historical bars or ticks during initialization; and query or persist its parameters and state. Convenience methods map long and short entries and exits to orders, while order submission and cancellation are gated by whether the strategy is actively trading.
A target-position extension turns a desired net position into orders. It estimates a limit price from the best ask or bid, with a one-tick adjustment and a cap at the market’s price limit when available; when only bars are available, it uses the latest close. If orders remain active, it requests their cancellation before recalculating. Live execution handles closing an opposing position before opening further exposure, while backtesting submits the position difference directly. The document explains mechanics rather than a trading signal: it gives no performance evidence and does not discuss slippage, partial fills, sizing rules, or safeguards for stale market data. Its behavior therefore depends on the surrounding engine and execution model.
Key ideas
- Strategy hooks provide places to process market data, order updates, and trades.
- Historical bar or tick data can be loaded to initialize strategy logic.
- Order helpers translate long and short entries and exits into direction and offset combinations.
- Target-position logic computes an order from the difference between desired and current exposure.
- Price selection uses top-of-book quotes or the latest bar close, adjusted by a tick increment.
- Live and simulated execution follow different procedures for reducing opposing exposure.
Tags
From a private course collection; the original is not published.