From 4cc93151c5266f77298989262def6778bb85a63f Mon Sep 17 00:00:00 2001 From: Pan Long Date: Sun, 31 Jan 2021 12:14:09 +0800 Subject: [PATCH 1/2] Fix a bug when compare sell_profit_offset It should be comparing the ratio instead of absolut profit. Also updated the comment. --- freqtrade/strategy/interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index c58d9aa5d..77d45b445 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -530,8 +530,8 @@ class IStrategy(ABC): current_time=date)) if (ask_strategy.get('sell_profit_only', False) - and trade.calc_profit(rate=rate) <= ask_strategy.get('sell_profit_offset', 0)): - # Negative profits and sell_profit_only - ignore sell signal + and trade.calc_profit_ratio(rate=rate) <= ask_strategy.get('sell_profit_offset', 0)): + # sell_profit_only and profit doesn't reach the offset - ignore sell signal sell_signal = False else: sell_signal = sell and not buy and ask_strategy.get('use_sell_signal', True) From 3d9b4034e683e9985c2695418eedba7bb0ac7070 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 2 Feb 2021 08:06:19 +0100 Subject: [PATCH 2/2] Use already calculated current_profit for sell_profit_offset comparison --- freqtrade/strategy/interface.py | 2 +- tests/test_freqtradebot.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 77d45b445..da4ce6c50 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -530,7 +530,7 @@ class IStrategy(ABC): current_time=date)) if (ask_strategy.get('sell_profit_only', False) - and trade.calc_profit_ratio(rate=rate) <= ask_strategy.get('sell_profit_offset', 0)): + and current_profit <= ask_strategy.get('sell_profit_offset', 0)): # sell_profit_only and profit doesn't reach the offset - ignore sell signal sell_signal = False else: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 2408afc87..e2b70257a 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3159,9 +3159,9 @@ def test_sell_profit_only_enable_profit(default_conf, limit_buy_order, limit_buy mocker.patch.multiple( 'freqtrade.exchange.Exchange', fetch_ticker=MagicMock(return_value={ - 'bid': 0.00002172, - 'ask': 0.00002173, - 'last': 0.00002172 + 'bid': 0.00001172, + 'ask': 0.00001173, + 'last': 0.00001172 }), buy=MagicMock(return_value=limit_buy_order_open), get_fee=fee,