Merge pull request #2366 from freqtrade/interface_noconf
Interface options should not use config
This commit is contained in:
commit
4228137dff
@ -95,7 +95,10 @@ class StrategyResolver(IResolver):
|
|||||||
logger.info("Override strategy '%s' with value in config file: %s.",
|
logger.info("Override strategy '%s' with value in config file: %s.",
|
||||||
attribute, config[attribute])
|
attribute, config[attribute])
|
||||||
elif hasattr(self.strategy, 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
|
# Explicitly check for None here as other "falsy" values are possible
|
||||||
elif default is not None:
|
elif default is not None:
|
||||||
setattr(self.strategy, attribute, default)
|
setattr(self.strategy, attribute, default)
|
||||||
|
@ -78,8 +78,8 @@ class IStrategy(ABC):
|
|||||||
|
|
||||||
# trailing stoploss
|
# trailing stoploss
|
||||||
trailing_stop: bool = False
|
trailing_stop: bool = False
|
||||||
trailing_stop_positive: float
|
trailing_stop_positive: Optional[float] = None
|
||||||
trailing_stop_positive_offset: float
|
trailing_stop_positive_offset: float = 0.0
|
||||||
trailing_only_offset_is_reached = False
|
trailing_only_offset_is_reached = False
|
||||||
|
|
||||||
# associated ticker interval
|
# associated ticker interval
|
||||||
@ -347,26 +347,23 @@ class IStrategy(ABC):
|
|||||||
decides to sell or not
|
decides to sell or not
|
||||||
:param current_profit: current profit in percent
|
: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
|
stop_loss_value = force_stoploss if force_stoploss else self.stoploss
|
||||||
|
|
||||||
# Initiate stoploss with open_rate. Does nothing if stoploss is already set.
|
# Initiate stoploss with open_rate. Does nothing if stoploss is already set.
|
||||||
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
||||||
|
|
||||||
if trailing_stop:
|
if self.trailing_stop:
|
||||||
# trailing stoploss handling
|
# trailing stoploss handling
|
||||||
sl_offset = self.config.get('trailing_stop_positive_offset') or 0.0
|
sl_offset = self.trailing_stop_positive_offset
|
||||||
tsl_only_offset = self.config.get('trailing_only_offset_is_reached', False)
|
|
||||||
|
|
||||||
# Make sure current_profit is calculated using high for backtesting.
|
# Make sure current_profit is calculated using high for backtesting.
|
||||||
high_profit = current_profit if not high else trade.calc_profit_percent(high)
|
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.
|
# 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
|
# Specific handling for trailing_stop_positive
|
||||||
if 'trailing_stop_positive' in self.config 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
|
||||||
stop_loss_value = self.config.get('trailing_stop_positive') # type: ignore
|
|
||||||
logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} "
|
logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} "
|
||||||
f"offset: {sl_offset:.4g} profit: {current_profit:.4f}%")
|
f"offset: {sl_offset:.4g} profit: {current_profit:.4f}%")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user