kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.55k stars 1.07k forks source link

Enhancement: Add order_validity and trade_validity Parameters to buy and sell Methods #1169

Open shajmanfaiz opened 2 months ago

shajmanfaiz commented 2 months ago

Expected Behavior

I'd like to request an enhancement to the Backtesting.py library that introduces two new parameters, order_validity and trade_validity, to the buy and sell methods within the Strategy class. order_validity = 10 the order auto cacels after 10 bar after the order if not filled and trade_validity = 20 the trade auto cancels after 20 bar after the order is filled and if trade not already exited (by sl or tp)

Implementation example

def buy( self, , size=1, limit=100, sl=95, tp=110, order_validity=10, trade_validity=20 ): def sell( self, , size=1, limit=100, sl=105, tp=90, order_validity=10, trade_validity=20 ):

Additional info

If anyone already has implemented or interested please comment down.