revise logic in should_sell
This commit is contained in:
parent
4aa6ebee04
commit
fefb4b23d0
@ -481,46 +481,39 @@ class IStrategy(ABC):
|
|||||||
current_profit = trade.calc_profit_ratio(current_rate)
|
current_profit = trade.calc_profit_ratio(current_rate)
|
||||||
config_ask_strategy = self.config.get('ask_strategy', {})
|
config_ask_strategy = self.config.get('ask_strategy', {})
|
||||||
|
|
||||||
roi_reached = self.min_roi_reached(trade=trade, current_profit=current_profit,
|
# if buy signal and ignore_roi is set, we don't need to evaluate min_roi.
|
||||||
current_time=date)
|
roi_reached = (not (buy and config_ask_strategy.get('ignore_roi_if_buy_signal', False))
|
||||||
|
and self.min_roi_reached(trade=trade, current_profit=current_profit,
|
||||||
|
current_time=date))
|
||||||
|
|
||||||
if stoplossflag.sell_flag:
|
if config_ask_strategy.get('sell_profit_only', False) and trade.calc_profit(rate=rate) <= 0:
|
||||||
|
# Negative profits and sell_profit_only - ignore sell signal
|
||||||
|
sell_signal = False
|
||||||
|
else:
|
||||||
|
sell_signal = sell and not buy and config_ask_strategy.get('use_sell_signal', True)
|
||||||
|
# TODO: return here if sell-signal should be favored over ROI
|
||||||
|
|
||||||
# When backtesting, in the case of trailing_stop_loss,
|
# Start evaluations
|
||||||
# make sure we don't make a profit higher than ROI.
|
# Sequence:
|
||||||
if stoplossflag.sell_type == SellType.TRAILING_STOP_LOSS and roi_reached:
|
# ROI (if not stoploss)
|
||||||
logger.debug(f"{trade.pair} - Required profit reached. sell_flag=True, "
|
# Sell-signal
|
||||||
f"sell_type=SellType.ROI")
|
# Stoploss
|
||||||
return SellCheckTuple(sell_flag=True, sell_type=SellType.ROI)
|
if roi_reached and stoplossflag.sell_type != SellType.STOP_LOSS:
|
||||||
|
|
||||||
logger.debug(f"{trade.pair} - Stoploss hit. sell_flag=True, "
|
|
||||||
f"sell_type={stoplossflag.sell_type}")
|
|
||||||
return stoplossflag
|
|
||||||
|
|
||||||
if buy and config_ask_strategy.get('ignore_roi_if_buy_signal', False):
|
|
||||||
# This one is noisy, commented out
|
|
||||||
# logger.debug(f"{trade.pair} - Buy signal still active. sell_flag=False")
|
|
||||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
|
||||||
|
|
||||||
# Check if minimal roi has been reached and no longer in buy conditions (avoiding a fee)
|
|
||||||
if roi_reached:
|
|
||||||
logger.debug(f"{trade.pair} - Required profit reached. sell_flag=True, "
|
logger.debug(f"{trade.pair} - Required profit reached. sell_flag=True, "
|
||||||
f"sell_type=SellType.ROI")
|
f"sell_type=SellType.ROI")
|
||||||
return SellCheckTuple(sell_flag=True, sell_type=SellType.ROI)
|
return SellCheckTuple(sell_flag=True, sell_type=SellType.ROI)
|
||||||
|
|
||||||
if config_ask_strategy.get('sell_profit_only', False):
|
if sell_signal:
|
||||||
# This one is noisy, commented out
|
|
||||||
# logger.debug(f"{trade.pair} - Checking if trade is profitable...")
|
|
||||||
if trade.calc_profit(rate=rate) <= 0:
|
|
||||||
# This one is noisy, commented out
|
|
||||||
# logger.debug(f"{trade.pair} - Trade is not profitable. sell_flag=False")
|
|
||||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
|
||||||
|
|
||||||
if sell and not buy and config_ask_strategy.get('use_sell_signal', True):
|
|
||||||
logger.debug(f"{trade.pair} - Sell signal received. sell_flag=True, "
|
logger.debug(f"{trade.pair} - Sell signal received. sell_flag=True, "
|
||||||
f"sell_type=SellType.SELL_SIGNAL")
|
f"sell_type=SellType.SELL_SIGNAL")
|
||||||
return SellCheckTuple(sell_flag=True, sell_type=SellType.SELL_SIGNAL)
|
return SellCheckTuple(sell_flag=True, sell_type=SellType.SELL_SIGNAL)
|
||||||
|
|
||||||
|
if stoplossflag.sell_flag:
|
||||||
|
|
||||||
|
logger.debug(f"{trade.pair} - Stoploss hit. sell_flag=True, "
|
||||||
|
f"sell_type={stoplossflag.sell_type}")
|
||||||
|
return stoplossflag
|
||||||
|
|
||||||
# This one is noisy, commented out...
|
# This one is noisy, commented out...
|
||||||
# logger.debug(f"{trade.pair} - No sell signal. sell_flag=False")
|
# logger.debug(f"{trade.pair} - No sell signal. sell_flag=False")
|
||||||
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
|
||||||
|
@ -3556,7 +3556,7 @@ def test_disable_ignore_roi_if_buy_signal(default_conf, limit_buy_order, limit_b
|
|||||||
# Test if buy-signal is absent
|
# Test if buy-signal is absent
|
||||||
patch_get_signal(freqtrade, value=(False, True))
|
patch_get_signal(freqtrade, value=(False, True))
|
||||||
assert freqtrade.handle_trade(trade) is True
|
assert freqtrade.handle_trade(trade) is True
|
||||||
assert trade.sell_reason == SellType.STOP_LOSS.value
|
assert trade.sell_reason == SellType.SELL_SIGNAL.value
|
||||||
|
|
||||||
|
|
||||||
def test_get_real_amount_quote(default_conf, trades_for_order, buy_order_fee, fee, caplog, mocker):
|
def test_get_real_amount_quote(default_conf, trades_for_order, buy_order_fee, fee, caplog, mocker):
|
||||||
|
Loading…
Reference in New Issue
Block a user