more work on stop losses
This commit is contained in:
parent
867fac7719
commit
250e84a42a
@ -197,16 +197,17 @@ class Analyze(object):
|
|||||||
current_profit = trade.calc_profit_percent(current_rate)
|
current_profit = trade.calc_profit_percent(current_rate)
|
||||||
|
|
||||||
if trade.stop_loss is None:
|
if trade.stop_loss is None:
|
||||||
# initially adjust the stop loss to it's default value
|
# initially adjust the stop loss to the base value
|
||||||
trade.adjust_stop_loss(current_rate, self.strategy.stoploss)
|
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:
|
if self.strategy.stoploss is not None and trade.stop_loss >= current_rate:
|
||||||
logger.debug('Stop loss hit.')
|
logger.debug('Stop loss hit.')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# update the stop loss afterwards, after all by definition it's supposed to be hanging
|
# update the stop loss afterwards, after all by definition it's supposed to be hanging
|
||||||
trade.adjust_stop_loss(current_rate, self.strategy.stoploss)
|
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
|
# Check if time matches and current rate is above threshold
|
||||||
time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60
|
time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60
|
||||||
|
@ -117,21 +117,20 @@ class Trade(_DECL_BASE):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
new_loss = Decimal(current_price * (1 - abs(stoploss)))
|
new_loss = Decimal(current_price * (1 - abs(stoploss)))
|
||||||
logger.debug("calculated stop loss at: {:.6f}".format(new_loss))
|
|
||||||
if self.stop_loss is None:
|
if self.stop_loss is None:
|
||||||
logger.debug("assigning new stop loss")
|
logger.debug("assigning new stop loss")
|
||||||
self.stop_loss = new_loss # no stop loss assigned yet
|
self.stop_loss = new_loss # no stop loss assigned yet
|
||||||
else:
|
else:
|
||||||
if _CONF.get('trailing_stop', True):
|
if new_loss > self.stop_loss: # stop losses only walk up, never down!
|
||||||
if new_loss > self.stop_loss: # stop losses only walk up, never down!
|
self.stop_loss = new_loss
|
||||||
self.stop_loss = new_loss
|
logger.debug("adjusted stop loss")
|
||||||
logger.debug("adjusted stop loss for {:.6f} and {:.6f} to {:.6f}".format(
|
|
||||||
current_price, stoploss, self.stop_loss)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.debug("keeping current stop loss of {:.6f}".format(self.stop_loss))
|
|
||||||
else:
|
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:
|
def update(self, order: Dict) -> None:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user