Improve stoploss test accuracy

This commit is contained in:
Matthias 2024-06-21 16:40:44 +02:00
parent f117e66f53
commit 93ed61a623

View File

@ -458,55 +458,66 @@ def test_min_roi_reached3(default_conf, fee) -> None:
ExitType.TRAILING_STOP_LOSS,
None,
),
(0.01, 0.96, ExitType.NONE, None, True, False, 0.05, 1, ExitType.NONE, None),
(0.05, 1, ExitType.NONE, None, True, False, -0.01, 1, ExitType.TRAILING_STOP_LOSS, None),
(0.01, 0.96, ExitType.NONE, None, True, False, 0.05, 0.998, ExitType.NONE, None),
(
0.05,
0.998,
ExitType.NONE,
None,
True,
False,
-0.01,
0.998,
ExitType.TRAILING_STOP_LOSS,
None,
),
# Default custom case - trails with 10%
(0.05, 0.95, ExitType.NONE, None, False, True, -0.02, 0.95, ExitType.NONE, None),
(0.05, 0.945, ExitType.NONE, None, False, True, -0.02, 0.945, ExitType.NONE, None),
(
0.05,
0.95,
0.945,
ExitType.NONE,
None,
False,
True,
-0.06,
0.95,
0.945,
ExitType.TRAILING_STOP_LOSS,
None,
),
(
0.05,
1,
0.998,
ExitType.NONE,
None,
False,
True,
-0.06,
1,
0.998,
ExitType.TRAILING_STOP_LOSS,
lambda **kwargs: -0.05,
),
(
0.05,
1,
0.998,
ExitType.NONE,
None,
False,
True,
0.09,
1.04,
1.036,
ExitType.NONE,
lambda **kwargs: -0.05,
),
(
0.05,
0.95,
0.945,
ExitType.NONE,
None,
False,
True,
0.09,
0.98,
0.981,
ExitType.NONE,
lambda current_profit, **kwargs: (
-0.1 if current_profit < 0.6 else -(current_profit * 2)
@ -552,6 +563,8 @@ def test_ft_stoploss_reached(
exchange="binance",
open_rate=1,
liquidation_price=liq,
price_precision=4,
precision_mode=2,
)
trade.adjust_min_max_rates(trade.open_rate, trade.open_rate)
strategy.trailing_stop = trailing
@ -577,7 +590,7 @@ def test_ft_stoploss_reached(
assert sl_flag.exit_flag is False
else:
assert sl_flag.exit_flag is True
assert round(trade.stop_loss, 2) == adjusted
assert round(trade.stop_loss, 3) == adjusted
current_rate2 = trade.open_rate * (1 + profit2)
sl_flag = strategy.ft_stoploss_reached(
@ -593,7 +606,7 @@ def test_ft_stoploss_reached(
assert sl_flag.exit_flag is False
else:
assert sl_flag.exit_flag is True
assert round(trade.stop_loss, 2) == adjusted2
assert round(trade.stop_loss, 3) == adjusted2
strategy.custom_stoploss = original_stopvalue