diff --git a/config.json.example b/config.json.example index 5b98a505a..63530d936 100644 --- a/config.json.example +++ b/config.json.example @@ -4,7 +4,9 @@ "stake_amount": 0.05, "fiat_display_currency": "USD", "dry_run": false, - "trailing_stop": false, + "trailing_stop": { + "positive" : 0.01 + }, "unfilledtimeout": 600, "bid_strategy": { "ask_last_balance": 0.0 diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index c1bae8303..7de3e95b2 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -203,20 +203,32 @@ class Analyze(object): # evaluate if the stoploss was hit if self.strategy.stoploss is not None and trade.stop_loss >= current_rate: - # just for debugging if 'trailing_stop' in self.config and self.config['trailing_stop']: logger.warning( "HIT STOP: current price at {:.6f}, stop loss is {:.6f}, " "initial stop loss was at {:.6f}, trade opened at {:.6f}".format( current_rate, trade.stop_loss, trade.initial_stop_loss, trade.open_rate)) - logger.debug("trailing stop saved us: {:.6f}".format(trade.stop_loss - trade.initial_stop_loss)) + logger.debug("trailing stop saved us: {:.6f}" + .format(trade.stop_loss - trade.initial_stop_loss)) logger.debug('Stop loss hit.') return True # update the stop loss afterwards, after all by definition it's supposed to be hanging if 'trailing_stop' in self.config and self.config['trailing_stop']: - trade.adjust_stop_loss(current_rate, self.strategy.stoploss) + + # check if we have a special stop loss for positive condition + # and if profit is positive + stop_loss_value = self.strategy.stoploss + if isinstance(self.config['trailing_stop'], dict) and \ + 'positive' in self.config['trailing_stop'] and \ + current_profit > 0: + + print("using positive stop loss mode: {} since we have profit {}".format( + self.config['trailing_stop']['positive'], current_profit)) + stop_loss_value = self.config['trailing_stop']['positive'] + + trade.adjust_stop_loss(current_rate, stop_loss_value) # Check if time matches and current rate is above threshold time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60 diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index 52aa17038..67cae492c 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -95,9 +95,12 @@ class Trade(_DECL_BASE): open_date = Column(DateTime, nullable=False, default=datetime.utcnow) close_date = Column(DateTime) open_order_id = Column(String) - stop_loss = Column(Float, nullable=False, default=0.0) # absolute value of the stop loss - initial_stop_loss = Column(Float, nullable=False, default=0.0) # absolute value of the initial stop loss - max_rate = Column(Float, nullable=False, default=0.0) # absolute value of the highest reached price + # absolute value of the stop loss + stop_loss = Column(Float, nullable=False, default=0.0) + # absolute value of the initial stop loss + initial_stop_loss = Column(Float, nullable=False, default=0.0) + # absolute value of the highest reached price + max_rate = Column(Float, nullable=False, default=0.0) def __repr__(self): return 'Trade(id={}, pair={}, amount={:.8f}, open_rate={:.8f}, open_since={})'.format( @@ -141,7 +144,7 @@ class Trade(_DECL_BASE): else: logger.debug("keeping current stop loss") - print( + logger.debug( "{} - current price {:.8f}, bought at {:.8f} and calculated " "stop loss is at: {:.8f} initial stop at {:.8f}. trailing stop loss saved us: {:.8f} " "and max observed rate was {:.8f}".format(