Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Time-in-Force (TIF) for limit orders #1285

Open
Labels
enhancementNew feature or request
@JohnyBuk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /