diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index cce3b6a0d..8b3eb46ca 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -232,10 +232,7 @@ class Backtesting: pair_data.loc[:, 'buy_tag'] = None # cleanup if buy_tag is exist df_analyzed = self.strategy.advise_sell( - self.strategy.advise_buy( - pair_data, - {'pair': pair} - ), + self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair} ).copy() # Trim startup period from analyzed dataframe diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 5c627df35..0db78aa39 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -285,13 +285,11 @@ class Hyperopt: # Apply parameters if HyperoptTools.has_space(self.config, 'buy'): self.backtesting.strategy.advise_buy = ( # type: ignore - self.custom_hyperopt.buy_strategy_generator(params_dict) - ) + self.custom_hyperopt.buy_strategy_generator(params_dict)) if HyperoptTools.has_space(self.config, 'sell'): self.backtesting.strategy.advise_sell = ( # type: ignore - self.custom_hyperopt.sell_strategy_generator(params_dict) - ) + self.custom_hyperopt.sell_strategy_generator(params_dict)) if HyperoptTools.has_space(self.config, 'protection'): for attr_name, attr in self.backtesting.strategy.enumerate_parameters('protection'): diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index afb5916f1..0d1f1598f 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -193,11 +193,13 @@ class StrategyResolver(IResolver): # register temp path with the bot abs_paths.insert(0, temp.resolve()) - strategy = StrategyResolver._load_object(paths=abs_paths, - object_name=strategy_name, - add_source=True, - kwargs={'config': config}, - ) + strategy = StrategyResolver._load_object( + paths=abs_paths, + object_name=strategy_name, + add_source=True, + kwargs={'config': config}, + ) + if strategy: strategy._populate_fun_len = len(getfullargspec(strategy.populate_indicators).args) strategy._buy_fun_len = len(getfullargspec(strategy.populate_buy_trend).args) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 21d0c70ae..50677c064 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -553,15 +553,22 @@ class IStrategy(ABC, HyperStrategyMixin): logger.debug(f'trigger: %s (pair=%s) {enter_type.value}=%s {exit_type.value}=%s', latest['date'], pair, str(enter), str(exit)) timeframe_seconds = timeframe_to_seconds(timeframe) - if self.ignore_expired_candle(latest_date=latest_date, - current_time=datetime.now(timezone.utc), - timeframe_seconds=timeframe_seconds, - enter=enter): + if self.ignore_expired_candle( + latest_date=latest_date, + current_time=datetime.now(timezone.utc), + timeframe_seconds=timeframe_seconds, + enter=enter + ): return False, exit, enter_tag_value return enter, exit, enter_tag_value - def ignore_expired_candle(self, latest_date: datetime, current_time: datetime, - timeframe_seconds: int, enter: bool): + def ignore_expired_candle( + self, + latest_date: datetime, + current_time: datetime, + timeframe_seconds: int, + enter: bool + ): if self.ignore_buying_expired_candle_after and enter: time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds)) return time_delta.total_seconds() > self.ignore_buying_expired_candle_after diff --git a/freqtrade/templates/sample_hyperopt.py b/freqtrade/templates/sample_hyperopt.py index c39558108..ca72e3740 100644 --- a/freqtrade/templates/sample_hyperopt.py +++ b/freqtrade/templates/sample_hyperopt.py @@ -46,7 +46,7 @@ class SampleHyperOpt(IHyperOpt): """ @staticmethod - def buy_indicator_space() -> List[Dimension]: + def indicator_space() -> List[Dimension]: """ Define your Hyperopt space for searching buy strategy parameters. """ @@ -63,8 +63,7 @@ class SampleHyperOpt(IHyperOpt): Categorical([True, False], name='fastd-enabled'), Categorical([True, False], name='adx-enabled'), Categorical([True, False], name='rsi-enabled'), - Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger'), - + Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger') ] @staticmethod @@ -157,7 +156,7 @@ class SampleHyperOpt(IHyperOpt): 'sell-macd_cross_signal', 'sell-sar_reversal'], name='sell-trigger' - ), + ) ] @staticmethod diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 7b7354bda..958f4ebed 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -750,6 +750,7 @@ def test_auto_hyperopt_interface(default_conf): # TODO-lev: Should these be 4,4 and 10? assert len(all_params['buy']) == 4 assert len(all_params['sell']) == 4 + # Number of Hyperoptable parameters assert all_params['count'] == 10 strategy.__class__.sell_rsi = IntParameter([0, 10], default=5, space='buy') diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index 8f8a71097..73c7cb5f7 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -385,13 +385,13 @@ def test_call_deprecated_function(result, monkeypatch, default_conf, caplog): assert isinstance(indicator_df, DataFrame) assert 'adx' in indicator_df.columns - buydf = strategy.advise_buy(result, metadata=metadata) - assert isinstance(buydf, DataFrame) - assert 'buy' in buydf.columns + enterdf = strategy.advise_buy(result, metadata=metadata) + assert isinstance(enterdf, DataFrame) + assert 'buy' in enterdf.columns - selldf = strategy.advise_sell(result, metadata=metadata) - assert isinstance(selldf, DataFrame) - assert 'sell' in selldf + exitdf = strategy.advise_sell(result, metadata=metadata) + assert isinstance(exitdf, DataFrame) + assert 'sell' in exitdf assert log_has("DEPRECATED: Please migrate to using 'timeframe' instead of 'ticker_interval'.", caplog)