From 9e133eb32e206c2d9c01da340f099c7cef191004 Mon Sep 17 00:00:00 2001 From: misagh Date: Tue, 8 Jan 2019 16:31:02 +0100 Subject: [PATCH] adding guard not to cancel the previous stop loss on exchange if market is falling quickly --- freqtrade/freqtradebot.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 02b55954e..513b27755 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -649,9 +649,19 @@ class FreqtradeBot(object): trade.update(order) result = True elif self.config.get('trailing_stop', False): - # check if trailing stoploss is enabled and stoploss value has changed + # if trailing stoploss is enabled we check if stoploss value has changed # in which case we cancel stoploss order and put another one with new # value immediately + + # This is a guard: there is a situation where market is going doing down fast + # the stoploss on exchange checked previously is not hit but + # it is too late and too risky to cancel the previous stoploss + if trade.stop_loss < self.exchange.get_ticker(trade.pair)['bid']: + logger.info('stoploss on exchange update: too risky to update stoploss as ' + 'current best bid price (%s) is higher than stoploss value (%s)', + self.exchange.get_ticker(trade.pair)['bid'], trade.stop_loss) + return result + if trade.stop_loss > order['info']['stopPrice']: # we check also if the update is neccesary update_beat = self.strategy.order_types['stoploss_on_exchange_interval']