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.34k stars 1.05k forks source link

Question regarding stoploss, takeprofit. #910

Open makovez opened 1 year ago

makovez commented 1 year ago

What does backtesting.py consider first? The low price or the high price of a candle to determine stop loss or take profit first?

kernc commented 1 year ago

When SL and TP are hit within the same bar, backtesting.py acts pessimistically, that is considering SL as hit first. https://github.com/kernc/backtesting.py/blob/0ce24d80b1bcb8120d95d31dc3bb351b1052a27d/backtesting/backtesting.py#L843-L848 Have to double check if this code works correctly with stop-limit orders. :thinking: