mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +00:00
Refresh open_rate and stoploss on order replacement.
This commit is contained in:
parent
8e9384e8e6
commit
1c20fb7638
|
@ -780,6 +780,8 @@ class Backtesting:
|
||||||
# interest_rate=interest_rate,
|
# interest_rate=interest_rate,
|
||||||
orders=[],
|
orders=[],
|
||||||
)
|
)
|
||||||
|
elif trade.nr_of_successful_entries == 0:
|
||||||
|
trade.open_rate = propose_rate
|
||||||
|
|
||||||
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
|
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
|
||||||
|
|
||||||
|
@ -940,6 +942,8 @@ class Backtesting:
|
||||||
requested_rate=requested_rate,
|
requested_rate=requested_rate,
|
||||||
requested_stake=(order.remaining * order.price),
|
requested_stake=(order.remaining * order.price),
|
||||||
direction='short' if trade.is_short else 'long')
|
direction='short' if trade.is_short else 'long')
|
||||||
|
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss,
|
||||||
|
initial=False, refresh=True)
|
||||||
else:
|
else:
|
||||||
# assumption: there can't be multiple open entry orders at any given time
|
# assumption: there can't be multiple open entry orders at any given time
|
||||||
return (trade.nr_of_successful_entries == 0)
|
return (trade.nr_of_successful_entries == 0)
|
||||||
|
|
|
@ -491,7 +491,7 @@ class LocalTrade():
|
||||||
self.stoploss_last_update = datetime.utcnow()
|
self.stoploss_last_update = datetime.utcnow()
|
||||||
|
|
||||||
def adjust_stop_loss(self, current_price: float, stoploss: float,
|
def adjust_stop_loss(self, current_price: float, stoploss: float,
|
||||||
initial: bool = False) -> None:
|
initial: bool = False, refresh: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
This adjusts the stop loss to it's most recently observed setting
|
This adjusts the stop loss to it's most recently observed setting
|
||||||
:param current_price: Current rate the asset is traded
|
:param current_price: Current rate the asset is traded
|
||||||
|
@ -516,8 +516,7 @@ class LocalTrade():
|
||||||
new_loss = max(self.liquidation_price, new_loss)
|
new_loss = max(self.liquidation_price, new_loss)
|
||||||
|
|
||||||
# no stop loss assigned yet
|
# no stop loss assigned yet
|
||||||
if self.initial_stop_loss_pct is None:
|
if self.initial_stop_loss_pct is None or refresh:
|
||||||
logger.debug(f"{self.pair} - Assigning new stoploss...")
|
|
||||||
self._set_stop_loss(new_loss, stoploss)
|
self._set_stop_loss(new_loss, stoploss)
|
||||||
self.initial_stop_loss = new_loss
|
self.initial_stop_loss = new_loss
|
||||||
self.initial_stop_loss_pct = -1 * abs(stoploss)
|
self.initial_stop_loss_pct = -1 * abs(stoploss)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user