SELL_SIGNAL -> EXIT_SIGNAL
This commit is contained in:
parent
0037754969
commit
93e332e506
@ -464,7 +464,7 @@ class Edge:
|
|||||||
if len(ohlc_columns) - 1 < exit_index:
|
if len(ohlc_columns) - 1 < exit_index:
|
||||||
break
|
break
|
||||||
|
|
||||||
exit_type = ExitType.SELL_SIGNAL
|
exit_type = ExitType.EXIT_SIGNAL
|
||||||
exit_price = ohlc_columns[exit_index, 0]
|
exit_price = ohlc_columns[exit_index, 0]
|
||||||
|
|
||||||
trade = {'pair': pair,
|
trade = {'pair': pair,
|
||||||
|
@ -9,7 +9,7 @@ class ExitType(Enum):
|
|||||||
STOP_LOSS = "stop_loss"
|
STOP_LOSS = "stop_loss"
|
||||||
STOPLOSS_ON_EXCHANGE = "stoploss_on_exchange"
|
STOPLOSS_ON_EXCHANGE = "stoploss_on_exchange"
|
||||||
TRAILING_STOP_LOSS = "trailing_stop_loss"
|
TRAILING_STOP_LOSS = "trailing_stop_loss"
|
||||||
SELL_SIGNAL = "sell_signal"
|
EXIT_SIGNAL = "sell_signal"
|
||||||
FORCE_SELL = "force_sell"
|
FORCE_SELL = "force_sell"
|
||||||
EMERGENCY_SELL = "emergency_sell"
|
EMERGENCY_SELL = "emergency_sell"
|
||||||
CUSTOM_SELL = "custom_sell"
|
CUSTOM_SELL = "custom_sell"
|
||||||
|
@ -395,7 +395,7 @@ class Backtesting:
|
|||||||
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
|
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
|
||||||
# call the custom exit price,with default value as previous closerate
|
# call the custom exit price,with default value as previous closerate
|
||||||
current_profit = trade.calc_profit_ratio(closerate)
|
current_profit = trade.calc_profit_ratio(closerate)
|
||||||
if sell.exit_type in (ExitType.SELL_SIGNAL, ExitType.CUSTOM_SELL):
|
if sell.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_SELL):
|
||||||
# Custom exit pricing only for sell-signals
|
# Custom exit pricing only for sell-signals
|
||||||
closerate = strategy_safe_wrapper(self.strategy.custom_exit_price,
|
closerate = strategy_safe_wrapper(self.strategy.custom_exit_price,
|
||||||
default_retval=closerate)(
|
default_retval=closerate)(
|
||||||
|
@ -795,7 +795,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
pass
|
pass
|
||||||
elif self.use_exit_signal and not enter:
|
elif self.use_exit_signal and not enter:
|
||||||
if exit_:
|
if exit_:
|
||||||
sell_signal = ExitType.SELL_SIGNAL
|
sell_signal = ExitType.EXIT_SIGNAL
|
||||||
else:
|
else:
|
||||||
trade_type = "exit_short" if trade.is_short else "sell"
|
trade_type = "exit_short" if trade.is_short else "sell"
|
||||||
custom_reason = strategy_safe_wrapper(self.custom_sell, default_retval=False)(
|
custom_reason = strategy_safe_wrapper(self.custom_sell, default_retval=False)(
|
||||||
@ -811,7 +811,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
custom_reason = custom_reason[:CUSTOM_SELL_MAX_LENGTH]
|
custom_reason = custom_reason[:CUSTOM_SELL_MAX_LENGTH]
|
||||||
else:
|
else:
|
||||||
custom_reason = None
|
custom_reason = None
|
||||||
if sell_signal in (ExitType.CUSTOM_SELL, ExitType.SELL_SIGNAL):
|
if sell_signal in (ExitType.CUSTOM_SELL, ExitType.EXIT_SIGNAL):
|
||||||
logger.debug(f"{trade.pair} - Sell signal received. "
|
logger.debug(f"{trade.pair} - Sell signal received. "
|
||||||
f"exit_type=ExitType.{sell_signal.name}" +
|
f"exit_type=ExitType.{sell_signal.name}" +
|
||||||
(f", custom_reason={custom_reason}" if custom_reason else ""))
|
(f", custom_reason={custom_reason}" if custom_reason else ""))
|
||||||
|
@ -95,8 +95,8 @@ tc1 = BTContainer(data=[
|
|||||||
[6, 5000, 5025, 4975, 4987, 6172, 0, 0], # should sell
|
[6, 5000, 5025, 4975, 4987, 6172, 0, 0], # should sell
|
||||||
],
|
],
|
||||||
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
||||||
trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=2),
|
trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=2),
|
||||||
BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=4, close_tick=6)]
|
BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=4, close_tick=6)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
|
# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
|
||||||
|
@ -22,7 +22,7 @@ tc0 = BTContainer(data=[
|
|||||||
[4, 5010, 5011, 4977, 4995, 6172, 0, 0],
|
[4, 5010, 5011, 4977, 4995, 6172, 0, 0],
|
||||||
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
||||||
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True,
|
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True,
|
||||||
trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)]
|
trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test 1: Stop-Loss Triggered 1% loss
|
# Test 1: Stop-Loss Triggered 1% loss
|
||||||
@ -406,7 +406,7 @@ tc25 = BTContainer(data=[
|
|||||||
[4, 5010, 5010, 4855, 4995, 6172, 0, 0], # Triggers stoploss + sellsignal acted on
|
[4, 5010, 5010, 4855, 4995, 6172, 0, 0], # Triggers stoploss + sellsignal acted on
|
||||||
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
||||||
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True,
|
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002, use_exit_signal=True,
|
||||||
trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)]
|
trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test 26: Sell with signal sell in candle 3 (ROI at signal candle)
|
# Test 26: Sell with signal sell in candle 3 (ROI at signal candle)
|
||||||
@ -435,7 +435,7 @@ tc27 = BTContainer(data=[
|
|||||||
[4, 5010, 5251, 4855, 4995, 6172, 0, 0], # Triggers ROI, sell-signal acted on
|
[4, 5010, 5251, 4855, 4995, 6172, 0, 0], # Triggers ROI, sell-signal acted on
|
||||||
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
||||||
stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.002, use_exit_signal=True,
|
stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.002, use_exit_signal=True,
|
||||||
trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)]
|
trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test 28: trailing_stop should raise so candle 3 causes a stoploss
|
# Test 28: trailing_stop should raise so candle 3 causes a stoploss
|
||||||
@ -548,7 +548,7 @@ tc34 = BTContainer(data=[
|
|||||||
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
[5, 4995, 4995, 4950, 4950, 6172, 0, 0]],
|
||||||
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002 * 5.0, use_exit_signal=True,
|
stop_loss=-0.01, roi={"0": 1}, profit_perc=0.002 * 5.0, use_exit_signal=True,
|
||||||
leverage=5.0,
|
leverage=5.0,
|
||||||
trades=[BTrade(exit_reason=ExitType.SELL_SIGNAL, open_tick=1, close_tick=4)]
|
trades=[BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=4)]
|
||||||
)
|
)
|
||||||
|
|
||||||
TESTS = [
|
TESTS = [
|
||||||
|
@ -11,7 +11,7 @@ from tests.conftest import get_patched_freqtradebot, log_has_re
|
|||||||
|
|
||||||
|
|
||||||
def generate_mock_trade(pair: str, fee: float, is_open: bool,
|
def generate_mock_trade(pair: str, fee: float, is_open: bool,
|
||||||
exit_reason: str = ExitType.SELL_SIGNAL,
|
exit_reason: str = ExitType.EXIT_SIGNAL,
|
||||||
min_ago_open: int = None, min_ago_close: int = None,
|
min_ago_open: int = None, min_ago_close: int = None,
|
||||||
profit_rate: float = 0.9
|
profit_rate: float = 0.9
|
||||||
):
|
):
|
||||||
|
@ -2135,7 +2135,7 @@ def test_handle_trade_use_exit_signal(
|
|||||||
else:
|
else:
|
||||||
patch_get_signal(freqtrade, enter_long=False, exit_long=True)
|
patch_get_signal(freqtrade, enter_long=False, exit_long=True)
|
||||||
assert freqtrade.handle_trade(trade)
|
assert freqtrade.handle_trade(trade)
|
||||||
assert log_has("ETH/USDT - Sell signal received. exit_type=ExitType.SELL_SIGNAL",
|
assert log_has("ETH/USDT - Sell signal received. exit_type=ExitType.EXIT_SIGNAL",
|
||||||
caplog)
|
caplog)
|
||||||
|
|
||||||
|
|
||||||
@ -3003,7 +3003,7 @@ def test_execute_trade_exit_custom_exit_price(
|
|||||||
freqtrade.execute_trade_exit(
|
freqtrade.execute_trade_exit(
|
||||||
trade=trade,
|
trade=trade,
|
||||||
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
limit=ticker_usdt_sell_up()['ask' if is_short else 'bid'],
|
||||||
exit_reason=SellCheckTuple(exit_type=ExitType.SELL_SIGNAL)
|
exit_reason=SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sell price must be different to default bid price
|
# Sell price must be different to default bid price
|
||||||
@ -3031,7 +3031,7 @@ def test_execute_trade_exit_custom_exit_price(
|
|||||||
'profit_ratio': profit_ratio,
|
'profit_ratio': profit_ratio,
|
||||||
'stake_currency': 'USDT',
|
'stake_currency': 'USDT',
|
||||||
'fiat_currency': 'USD',
|
'fiat_currency': 'USD',
|
||||||
'exit_reason': ExitType.SELL_SIGNAL.value,
|
'exit_reason': ExitType.EXIT_SIGNAL.value,
|
||||||
'open_date': ANY,
|
'open_date': ANY,
|
||||||
'close_date': ANY,
|
'close_date': ANY,
|
||||||
'close_rate': ANY,
|
'close_rate': ANY,
|
||||||
@ -3403,18 +3403,18 @@ def test_execute_trade_exit_insufficient_funds_error(default_conf_usdt, ticker_u
|
|||||||
|
|
||||||
@pytest.mark.parametrize('profit_only,bid,ask,handle_first,handle_second,exit_type,is_short', [
|
@pytest.mark.parametrize('profit_only,bid,ask,handle_first,handle_second,exit_type,is_short', [
|
||||||
# Enable profit
|
# Enable profit
|
||||||
(True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, False),
|
(True, 2.18, 2.2, False, True, ExitType.EXIT_SIGNAL.value, False),
|
||||||
(True, 2.18, 2.2, False, True, ExitType.SELL_SIGNAL.value, True),
|
(True, 2.18, 2.2, False, True, ExitType.EXIT_SIGNAL.value, True),
|
||||||
# # Disable profit
|
# # Disable profit
|
||||||
(False, 3.19, 3.2, True, False, ExitType.SELL_SIGNAL.value, False),
|
(False, 3.19, 3.2, True, False, ExitType.EXIT_SIGNAL.value, False),
|
||||||
(False, 3.19, 3.2, True, False, ExitType.SELL_SIGNAL.value, True),
|
(False, 3.19, 3.2, True, False, ExitType.EXIT_SIGNAL.value, True),
|
||||||
# # Enable loss
|
# # Enable loss
|
||||||
# # * Shouldn't this be ExitType.STOP_LOSS.value
|
# # * Shouldn't this be ExitType.STOP_LOSS.value
|
||||||
(True, 0.21, 0.22, False, False, None, False),
|
(True, 0.21, 0.22, False, False, None, False),
|
||||||
(True, 2.41, 2.42, False, False, None, True),
|
(True, 2.41, 2.42, False, False, None, True),
|
||||||
# Disable loss
|
# Disable loss
|
||||||
(False, 0.10, 0.22, True, False, ExitType.SELL_SIGNAL.value, False),
|
(False, 0.10, 0.22, True, False, ExitType.EXIT_SIGNAL.value, False),
|
||||||
(False, 0.10, 0.22, True, False, ExitType.SELL_SIGNAL.value, True),
|
(False, 0.10, 0.22, True, False, ExitType.EXIT_SIGNAL.value, True),
|
||||||
])
|
])
|
||||||
def test_sell_profit_only(
|
def test_sell_profit_only(
|
||||||
default_conf_usdt, limit_order, limit_order_open, is_short,
|
default_conf_usdt, limit_order, limit_order_open, is_short,
|
||||||
@ -3441,7 +3441,7 @@ def test_sell_profit_only(
|
|||||||
})
|
})
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short)
|
patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short)
|
||||||
if exit_type == ExitType.SELL_SIGNAL.value:
|
if exit_type == ExitType.EXIT_SIGNAL.value:
|
||||||
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
||||||
else:
|
else:
|
||||||
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple(
|
freqtrade.strategy.stop_loss_reached = MagicMock(return_value=SellCheckTuple(
|
||||||
|
@ -53,7 +53,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
|||||||
# Sell 3rd trade (not called for the first trade)
|
# Sell 3rd trade (not called for the first trade)
|
||||||
should_sell_mock = MagicMock(side_effect=[
|
should_sell_mock = MagicMock(side_effect=[
|
||||||
SellCheckTuple(exit_type=ExitType.NONE),
|
SellCheckTuple(exit_type=ExitType.NONE),
|
||||||
SellCheckTuple(exit_type=ExitType.SELL_SIGNAL)]
|
SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL)]
|
||||||
)
|
)
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Binance.stoploss', stoploss)
|
mocker.patch('freqtrade.exchange.Binance.stoploss', stoploss)
|
||||||
@ -119,7 +119,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
|||||||
assert trade.is_open
|
assert trade.is_open
|
||||||
|
|
||||||
trade = trades[2]
|
trade = trades[2]
|
||||||
assert trade.exit_reason == ExitType.SELL_SIGNAL.value
|
assert trade.exit_reason == ExitType.EXIT_SIGNAL.value
|
||||||
assert not trade.is_open
|
assert not trade.is_open
|
||||||
|
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc
|
|||||||
)
|
)
|
||||||
should_sell_mock = MagicMock(side_effect=[
|
should_sell_mock = MagicMock(side_effect=[
|
||||||
SellCheckTuple(exit_type=ExitType.NONE),
|
SellCheckTuple(exit_type=ExitType.NONE),
|
||||||
SellCheckTuple(exit_type=ExitType.SELL_SIGNAL),
|
SellCheckTuple(exit_type=ExitType.EXIT_SIGNAL),
|
||||||
SellCheckTuple(exit_type=ExitType.NONE),
|
SellCheckTuple(exit_type=ExitType.NONE),
|
||||||
SellCheckTuple(exit_type=ExitType.NONE),
|
SellCheckTuple(exit_type=ExitType.NONE),
|
||||||
SellCheckTuple(exit_type=ExitType.NONE)]
|
SellCheckTuple(exit_type=ExitType.NONE)]
|
||||||
|
Loading…
Reference in New Issue
Block a user