trade_on_close
not followed when SL/TP hit in the same candle.
#945
Labels
duplicate
This issue or pull request already exists
Expected Behavior
When using the
trade_on_close=False
feature, trades will always occur on the following candle to which a trade was placed.Actual Behavior
When a SL/TP is hit on the same candle a trade is placed, the logic does not cater for
trade_on_close=False
and instead places and closes the trade on the current candle.I believe this is due to the check on line 908 of backtesting.py, which after a opening a trade with the correct
time_index
(the next candle in the backtest), instructs the backtest to reprocess orders if the trade is a market order and does not cater for thetrade_on_close
setting. This results in the SL/TP being checked for a trade that should not yet exist whentrade_on_close=False
.backtesting.py/backtesting/backtesting.py
Lines 900 to 920 in 0107d4a
The text was updated successfully, but these errors were encountered: