diff --git a/docs/hyperopt.md b/docs/hyperopt.md index e11c93748..f869b9ac1 100644 --- a/docs/hyperopt.md +++ b/docs/hyperopt.md @@ -433,7 +433,7 @@ class MyAwesomeStrategy(IStrategy): stoploss = -0.05 timeframe = '15m' # Define the parameter spaces - coolback_lookback = IntParameter(2, 48, default=5, space="protection", optimize=True) + cooldown_lookback = IntParameter(2, 48, default=5, space="protection", optimize=True) stop_duration = IntParameter(12, 200, default=5, space="protection", optimize=True) use_stop_protection = CategoricalParameter([True, False], default=True, space="protection", optimize=True) @@ -444,7 +444,7 @@ class MyAwesomeStrategy(IStrategy): prot.append({ "method": "CooldownPeriod", - "stop_duration_candles": self.coolback_lookback.value + "stop_duration_candles": self.cooldown_lookback.value }) if self.use_stop_protection.value: prot.append({ diff --git a/freqtrade/strategy/hyper.py b/freqtrade/strategy/hyper.py index e143dda7e..b9f586ac5 100644 --- a/freqtrade/strategy/hyper.py +++ b/freqtrade/strategy/hyper.py @@ -294,7 +294,8 @@ class HyperStrategyMixin(object): :return: """ if category not in ('buy', 'sell', 'protection', None): - raise OperationalException('Category must be one of: "buy", "sell", "protection", None.') + raise OperationalException( + 'Category must be one of: "buy", "sell", "protection", None.') if category is None: params = self.ft_buy_params + self.ft_sell_params + self.ft_protection_params diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index ef4b85beb..077fb516d 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -1003,6 +1003,8 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None: hyperopt_conf.update({ 'strategy': 'HyperoptableStrategy', 'user_data_dir': Path(tmpdir), + 'hyperopt_random_state': 42, + 'spaces': ['buy', 'sell', 'protection'] }) hyperopt = Hyperopt(hyperopt_conf) assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto) @@ -1010,12 +1012,18 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None: assert hyperopt.backtesting.strategy.buy_rsi.in_space is True assert hyperopt.backtesting.strategy.buy_rsi.value == 35 + assert hyperopt.backtesting.strategy.sell_rsi.value == 74 + assert hyperopt.backtesting.strategy.protection_cooldown_lookback.value == 30 buy_rsi_range = hyperopt.backtesting.strategy.buy_rsi.range assert isinstance(buy_rsi_range, range) # Range from 0 - 50 (inclusive) assert len(list(buy_rsi_range)) == 51 hyperopt.start() + # All values should've changed. + assert hyperopt.backtesting.strategy.protection_cooldown_lookback.value != 30 + assert hyperopt.backtesting.strategy.buy_rsi.value != 35 + assert hyperopt.backtesting.strategy.sell_rsi.value != 74 def test_SKDecimal(): diff --git a/tests/strategy/strats/hyperoptable_strategy.py b/tests/strategy/strats/hyperoptable_strategy.py index cc4734e13..9d332e243 100644 --- a/tests/strategy/strats/hyperoptable_strategy.py +++ b/tests/strategy/strats/hyperoptable_strategy.py @@ -64,6 +64,17 @@ class HyperoptableStrategy(IStrategy): sell_rsi = IntParameter(low=50, high=100, default=70, space='sell') sell_minusdi = DecimalParameter(low=0, high=1, default=0.5001, decimals=3, space='sell', load=False) + protection_cooldown_lookback = IntParameter([0, 50], default=30) + + @property + def protections(self): + prot = [] + + prot.append({ + "method": "CooldownPeriod", + "stop_duration_candles": self.protection_cooldown_lookback.value + }) + return prot def informative_pairs(self): """