more work on stop losses

This commit is contained in:
Gert Wohlgemuth 2018-05-10 16:50:04 -07:00
parent 867fac7719
commit 250e84a42a
2 changed files with 14 additions and 14 deletions

View File

@ -197,15 +197,16 @@ class Analyze(object):
current_profit = trade.calc_profit_percent(current_rate)
if trade.stop_loss is None:
# initially adjust the stop loss to it's default value
trade.adjust_stop_loss(current_rate, self.strategy.stoploss)
# initially adjust the stop loss to the base value
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss)
# evaluate stop loss, before we continue
# evaluate if the stoploss was hit
if self.strategy.stoploss is not None and trade.stop_loss >= current_rate:
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 time matches and current rate is above threshold

View File

@ -117,21 +117,20 @@ class Trade(_DECL_BASE):
"""
new_loss = Decimal(current_price * (1 - abs(stoploss)))
logger.debug("calculated stop loss at: {:.6f}".format(new_loss))
if self.stop_loss is None:
logger.debug("assigning new stop loss")
self.stop_loss = new_loss # no stop loss assigned yet
else:
if _CONF.get('trailing_stop', True):
if new_loss > self.stop_loss: # stop losses only walk up, never down!
self.stop_loss = new_loss
logger.debug("adjusted stop loss for {:.6f} and {:.6f} to {:.6f}".format(
current_price, stoploss, self.stop_loss)
)
logger.debug("adjusted stop loss")
else:
logger.debug("keeping current stop loss of {:.6f}".format(self.stop_loss))
else:
print("utilizing fixed stop")
logger.debug("keeping current stop loss")
print("{} - current price {:.6f}, calculated stop loss at: {:.6f} old loss at {:.6f}".format(self.id, current_price,
new_loss,
self.stop_loss))
def update(self, order: Dict) -> None:
"""