From 4d1488498cb3b884d21eb8c4d3690810bb5d79bc Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 11 Oct 2019 08:55:31 +0200 Subject: [PATCH 1/4] stoploss_reached should not use config --- freqtrade/strategy/interface.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index b35ebabbb..4d18e5232 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -79,7 +79,7 @@ class IStrategy(ABC): # trailing stoploss trailing_stop: bool = False trailing_stop_positive: float - trailing_stop_positive_offset: float + trailing_stop_positive_offset: float = 0.0 trailing_only_offset_is_reached = False # associated ticker interval @@ -347,22 +347,20 @@ class IStrategy(ABC): decides to sell or not :param current_profit: current profit in percent """ - trailing_stop = self.config.get('trailing_stop', False) stop_loss_value = force_stoploss if force_stoploss else self.stoploss # Initiate stoploss with open_rate. Does nothing if stoploss is already set. trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True) - if trailing_stop: + if self.trailing_stop: # trailing stoploss handling - sl_offset = self.config.get('trailing_stop_positive_offset') or 0.0 - tsl_only_offset = self.config.get('trailing_only_offset_is_reached', False) + sl_offset = self.trailing_stop_positive_offset # Make sure current_profit is calculated using high for backtesting. high_profit = current_profit if not high else trade.calc_profit_percent(high) # Don't update stoploss if trailing_only_offset_is_reached is true. - if not (tsl_only_offset and high_profit < sl_offset): + if not (self.trailing_only_offset_is_reached and high_profit < sl_offset): # Specific handling for trailing_stop_positive if 'trailing_stop_positive' in self.config and high_profit > sl_offset: # Ignore mypy error check in configuration that this is a float From ff7a3cc885ec9ce26d50ca002fd2b228d666fd89 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 11 Oct 2019 09:05:21 +0200 Subject: [PATCH 2/4] remove last occurance of config. from stop_loss_reached --- freqtrade/strategy/interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 4d18e5232..9c6936c20 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -362,9 +362,9 @@ class IStrategy(ABC): # Don't update stoploss if trailing_only_offset_is_reached is true. if not (self.trailing_only_offset_is_reached and high_profit < sl_offset): # Specific handling for trailing_stop_positive - if 'trailing_stop_positive' in self.config and high_profit > sl_offset: + if 'trailing_stop_positive' in self.__dict__ and high_profit > sl_offset: # Ignore mypy error check in configuration that this is a float - stop_loss_value = self.config.get('trailing_stop_positive') # type: ignore + stop_loss_value = self.trailing_stop_positive logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} " f"offset: {sl_offset:.4g} profit: {current_profit:.4f}%") From 4c1705fb1e552d13f854934dc23acac5b8bf73d5 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Fri, 11 Oct 2019 22:59:13 +0300 Subject: [PATCH 3/4] No specific handling for trailing_stop_positive --- freqtrade/resolvers/strategy_resolver.py | 5 ++++- freqtrade/strategy/interface.py | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 43197e5bc..b9c641853 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -95,7 +95,10 @@ class StrategyResolver(IResolver): logger.info("Override strategy '%s' with value in config file: %s.", attribute, config[attribute]) elif hasattr(self.strategy, attribute): - config[attribute] = getattr(self.strategy, attribute) + val = getattr(self.strategy, attribute) + # None's cannot exist in the config, so do not copy them + if val is not None: + config[attribute] = val # Explicitly check for None here as other "falsy" values are possible elif default is not None: setattr(self.strategy, attribute, default) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 9c6936c20..e4cfe0088 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -78,7 +78,7 @@ class IStrategy(ABC): # trailing stoploss trailing_stop: bool = False - trailing_stop_positive: float + trailing_stop_positive: Optional[float] = None trailing_stop_positive_offset: float = 0.0 trailing_only_offset_is_reached = False @@ -361,8 +361,7 @@ class IStrategy(ABC): # Don't update stoploss if trailing_only_offset_is_reached is true. if not (self.trailing_only_offset_is_reached and high_profit < sl_offset): - # Specific handling for trailing_stop_positive - if 'trailing_stop_positive' in self.__dict__ and high_profit > sl_offset: + if self.trailing_stop_positive is not None and high_profit > sl_offset: # Ignore mypy error check in configuration that this is a float stop_loss_value = self.trailing_stop_positive logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} " From 3c8d27d0985430254d8d7371e790a56f3ddef8bc Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Oct 2019 09:54:03 +0200 Subject: [PATCH 4/4] remove correct comment ... --- freqtrade/strategy/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index e4cfe0088..014ca9968 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -361,8 +361,8 @@ class IStrategy(ABC): # Don't update stoploss if trailing_only_offset_is_reached is true. if not (self.trailing_only_offset_is_reached and high_profit < sl_offset): + # Specific handling for trailing_stop_positive if self.trailing_stop_positive is not None and high_profit > sl_offset: - # Ignore mypy error check in configuration that this is a float stop_loss_value = self.trailing_stop_positive logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} " f"offset: {sl_offset:.4g} profit: {current_profit:.4f}%")