Add trailing-stop to strategy
This commit is contained in:
parent
29db2078d6
commit
4599c80e79
@ -56,6 +56,33 @@ class StrategyResolver(IResolver):
|
|||||||
else:
|
else:
|
||||||
config['stoploss'] = self.strategy.stoploss
|
config['stoploss'] = self.strategy.stoploss
|
||||||
|
|
||||||
|
if 'trailing_stop' in config:
|
||||||
|
self.strategy.trailing_stop = config['trailing_stop']
|
||||||
|
logger.info(
|
||||||
|
"Override strategy 'trailing_stop' with value in config file: %s.",
|
||||||
|
config['trailing_stop']
|
||||||
|
)
|
||||||
|
elif hasattr(self.strategy, "trailing_stop"):
|
||||||
|
config['trailing_stop'] = self.strategy.trailing_stop
|
||||||
|
|
||||||
|
if 'trailing_stop_positive' in config:
|
||||||
|
self.strategy.trailing_stop_positive = config['trailing_stop_positive']
|
||||||
|
logger.info(
|
||||||
|
"Override strategy 'trailing_stop_positive' with value in config file: %s.",
|
||||||
|
config['trailing_stop_positive']
|
||||||
|
)
|
||||||
|
elif hasattr(self.strategy, "trailing_stop_positive"):
|
||||||
|
config['trailing_stop_positive'] = self.strategy.trailing_stop_positive
|
||||||
|
|
||||||
|
if 'trailing_stop_positive_offset' in config:
|
||||||
|
self.strategy.trailing_stop_positive_offset = config['trailing_stop_positive_offset']
|
||||||
|
logger.info(
|
||||||
|
"Override strategy 'trailing_stop_positive_offset' with value in config file: %s.",
|
||||||
|
config['trailing_stop_positive_offset']
|
||||||
|
)
|
||||||
|
elif hasattr(self.strategy, "trailing_stop_positive_offset"):
|
||||||
|
config['trailing_stop_positive_offset'] = self.strategy.trailing_stop_positive_offset
|
||||||
|
|
||||||
if 'ticker_interval' in config:
|
if 'ticker_interval' in config:
|
||||||
self.strategy.ticker_interval = config['ticker_interval']
|
self.strategy.ticker_interval = config['ticker_interval']
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -67,6 +67,11 @@ class IStrategy(ABC):
|
|||||||
# associated stoploss
|
# associated stoploss
|
||||||
stoploss: float
|
stoploss: float
|
||||||
|
|
||||||
|
# trailing stoploss
|
||||||
|
trailing_stop: bool = False
|
||||||
|
trailing_stop_positive: float
|
||||||
|
trailing_stop_positive_offset: float
|
||||||
|
|
||||||
# associated ticker interval
|
# associated ticker interval
|
||||||
ticker_interval: str
|
ticker_interval: str
|
||||||
|
|
||||||
|
@ -150,6 +150,45 @@ def test_strategy_override_stoploss(caplog):
|
|||||||
) in caplog.record_tuples
|
) in caplog.record_tuples
|
||||||
|
|
||||||
|
|
||||||
|
def test_strategy_override_trailing_stop(caplog):
|
||||||
|
caplog.set_level(logging.INFO)
|
||||||
|
config = {
|
||||||
|
'strategy': 'DefaultStrategy',
|
||||||
|
'trailing_stop': True
|
||||||
|
}
|
||||||
|
resolver = StrategyResolver(config)
|
||||||
|
|
||||||
|
assert resolver.strategy.trailing_stop
|
||||||
|
assert isinstance(resolver.strategy.trailing_stop, bool)
|
||||||
|
assert ('freqtrade.resolvers.strategy_resolver',
|
||||||
|
logging.INFO,
|
||||||
|
"Override strategy 'trailing_stop' with value in config file: True."
|
||||||
|
) in caplog.record_tuples
|
||||||
|
|
||||||
|
|
||||||
|
def test_strategy_override_trailing_stop_positive(caplog):
|
||||||
|
caplog.set_level(logging.INFO)
|
||||||
|
config = {
|
||||||
|
'strategy': 'DefaultStrategy',
|
||||||
|
'trailing_stop_positive': -0.1,
|
||||||
|
'trailing_stop_positive_offset': -0.2
|
||||||
|
|
||||||
|
}
|
||||||
|
resolver = StrategyResolver(config)
|
||||||
|
|
||||||
|
assert resolver.strategy.trailing_stop_positive == -0.1
|
||||||
|
assert ('freqtrade.resolvers.strategy_resolver',
|
||||||
|
logging.INFO,
|
||||||
|
"Override strategy 'trailing_stop_positive' with value in config file: -0.1."
|
||||||
|
) in caplog.record_tuples
|
||||||
|
|
||||||
|
assert resolver.strategy.trailing_stop_positive_offset == -0.2
|
||||||
|
assert ('freqtrade.resolvers.strategy_resolver',
|
||||||
|
logging.INFO,
|
||||||
|
"Override strategy 'trailing_stop_positive' with value in config file: -0.1."
|
||||||
|
) in caplog.record_tuples
|
||||||
|
|
||||||
|
|
||||||
def test_strategy_override_ticker_interval(caplog):
|
def test_strategy_override_ticker_interval(caplog):
|
||||||
caplog.set_level(logging.INFO)
|
caplog.set_level(logging.INFO)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user