Description
Enhancement description
Currently, backtesting.py allows the placement of limit orders. However, these orders appear to remain "Good-Til-Cancelled" (GTC) indefinitely if not immediately triggered. There is no built-in mechanism to define an expiry date or a time-in-force (TIF) for these pending orders.
This limitation significantly impacts the realism of backtesting, as many real-world trading strategies and brokers require or benefit from orders that automatically expire after a certain period (e.g., end of day, after X bars, after Y days).
Without TIF/expiry options, users are forced to manually implement order cancellation logic within their strategy code (next() method), which can be complex, error-prone, and less efficient. This also adds unnecessary overhead and reduces the clarity of the trading logic.
I would appreciate extending the buy() and sell() methods to allow specifying a time-in-force or expiry for limit orders.