Merge branch 'StopLossSupport' into wohlgemuth
This commit is contained in:
commit
5c5cab58ca
@ -4,7 +4,9 @@
|
|||||||
"stake_amount": 0.05,
|
"stake_amount": 0.05,
|
||||||
"fiat_display_currency": "USD",
|
"fiat_display_currency": "USD",
|
||||||
"dry_run": false,
|
"dry_run": false,
|
||||||
"trailing_stop": false,
|
"trailing_stop": {
|
||||||
|
"positive" : 0.01
|
||||||
|
},
|
||||||
"unfilledtimeout": 600,
|
"unfilledtimeout": 600,
|
||||||
"bid_strategy": {
|
"bid_strategy": {
|
||||||
"ask_last_balance": 0.0
|
"ask_last_balance": 0.0
|
||||||
|
@ -203,20 +203,32 @@ class Analyze(object):
|
|||||||
# evaluate if the stoploss was hit
|
# 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:
|
||||||
|
|
||||||
# just for debugging
|
|
||||||
if 'trailing_stop' in self.config and self.config['trailing_stop']:
|
if 'trailing_stop' in self.config and self.config['trailing_stop']:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"HIT STOP: current price at {:.6f}, stop loss is {:.6f}, "
|
"HIT STOP: current price at {:.6f}, stop loss is {:.6f}, "
|
||||||
"initial stop loss was at {:.6f}, trade opened at {:.6f}".format(
|
"initial stop loss was at {:.6f}, trade opened at {:.6f}".format(
|
||||||
current_rate, trade.stop_loss, trade.initial_stop_loss, trade.open_rate))
|
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.')
|
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
|
||||||
if 'trailing_stop' in self.config and self.config['trailing_stop']:
|
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
|
# 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
|
||||||
|
@ -95,9 +95,12 @@ class Trade(_DECL_BASE):
|
|||||||
open_date = Column(DateTime, nullable=False, default=datetime.utcnow)
|
open_date = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||||
close_date = Column(DateTime)
|
close_date = Column(DateTime)
|
||||||
open_order_id = Column(String)
|
open_order_id = Column(String)
|
||||||
stop_loss = Column(Float, nullable=False, default=0.0) # absolute value of the stop loss
|
# absolute value of the stop loss
|
||||||
initial_stop_loss = Column(Float, nullable=False, default=0.0) # absolute value of the initial stop loss
|
stop_loss = Column(Float, nullable=False, default=0.0)
|
||||||
max_rate = Column(Float, nullable=False, default=0.0) # absolute value of the highest reached price
|
# 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):
|
def __repr__(self):
|
||||||
return 'Trade(id={}, pair={}, amount={:.8f}, open_rate={:.8f}, open_since={})'.format(
|
return 'Trade(id={}, pair={}, amount={:.8f}, open_rate={:.8f}, open_since={})'.format(
|
||||||
@ -141,7 +144,7 @@ class Trade(_DECL_BASE):
|
|||||||
else:
|
else:
|
||||||
logger.debug("keeping current stop loss")
|
logger.debug("keeping current stop loss")
|
||||||
|
|
||||||
print(
|
logger.debug(
|
||||||
"{} - current price {:.8f}, bought at {:.8f} and calculated "
|
"{} - current price {:.8f}, bought at {:.8f} and calculated "
|
||||||
"stop loss is at: {:.8f} initial stop at {:.8f}. trailing stop loss saved us: {:.8f} "
|
"stop loss is at: {:.8f} initial stop at {:.8f}. trailing stop loss saved us: {:.8f} "
|
||||||
"and max observed rate was {:.8f}".format(
|
"and max observed rate was {:.8f}".format(
|
||||||
|
Loading…
Reference in New Issue
Block a user