Merge pull request #4941 from brookmiles/fix-stoploss-above-candle

prevent backtest stoploss trade price being set above candle high
This commit is contained in:
Matthias
2021-05-19 06:20:35 +02:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@@ -216,6 +216,12 @@ class Backtesting:
"""
# Special handling if high or low hit STOP_LOSS or ROI
if sell.sell_type in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS):
if trade.stop_loss > sell_row[HIGH_IDX]:
# our stoploss was already higher than candle high,
# possibly due to a cancelled trade exit.
# sell at open price.
return sell_row[OPEN_IDX]
# Set close_rate to stoploss
return trade.stop_loss
elif sell.sell_type == (SellType.ROI):