mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Fix exit_reason assignment in backtesting
This commit is contained in:
parent
a8f064a8cb
commit
a0b25938f4
|
@ -535,6 +535,7 @@ class Backtesting:
|
||||||
|
|
||||||
if exit_.exit_flag:
|
if exit_.exit_flag:
|
||||||
trade.close_date = exit_candle_time
|
trade.close_date = exit_candle_time
|
||||||
|
exit_reason = exit_.exit_reason
|
||||||
|
|
||||||
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
|
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
|
||||||
try:
|
try:
|
||||||
|
@ -545,6 +546,15 @@ class Backtesting:
|
||||||
current_profit = trade.calc_profit_ratio(closerate)
|
current_profit = trade.calc_profit_ratio(closerate)
|
||||||
order_type = self.strategy.order_types['exit']
|
order_type = self.strategy.order_types['exit']
|
||||||
if exit_.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_EXIT):
|
if exit_.exit_type in (ExitType.EXIT_SIGNAL, ExitType.CUSTOM_EXIT):
|
||||||
|
# Checks and adds an exit tag, after checking that the length of the
|
||||||
|
# row has the length for an exit tag column
|
||||||
|
if(
|
||||||
|
len(row) > EXIT_TAG_IDX
|
||||||
|
and row[EXIT_TAG_IDX] is not None
|
||||||
|
and len(row[EXIT_TAG_IDX]) > 0
|
||||||
|
and exit_.exit_type in (ExitType.EXIT_SIGNAL,)
|
||||||
|
):
|
||||||
|
exit_reason = row[EXIT_TAG_IDX]
|
||||||
# Custom exit pricing only for exit-signals
|
# Custom exit pricing only for exit-signals
|
||||||
if order_type == 'limit':
|
if order_type == 'limit':
|
||||||
closerate = strategy_safe_wrapper(self.strategy.custom_exit_price,
|
closerate = strategy_safe_wrapper(self.strategy.custom_exit_price,
|
||||||
|
@ -552,7 +562,7 @@ class Backtesting:
|
||||||
pair=trade.pair, trade=trade,
|
pair=trade.pair, trade=trade,
|
||||||
current_time=exit_candle_time,
|
current_time=exit_candle_time,
|
||||||
proposed_rate=closerate, current_profit=current_profit,
|
proposed_rate=closerate, current_profit=current_profit,
|
||||||
exit_tag=exit_.exit_reason)
|
exit_tag=exit_reason)
|
||||||
# We can't place orders lower than current low.
|
# We can't place orders lower than current low.
|
||||||
# freqtrade does not support this in live, and the order would fill immediately
|
# freqtrade does not support this in live, and the order would fill immediately
|
||||||
if trade.is_short:
|
if trade.is_short:
|
||||||
|
@ -566,22 +576,12 @@ class Backtesting:
|
||||||
pair=trade.pair, trade=trade, order_type='limit', amount=trade.amount,
|
pair=trade.pair, trade=trade, order_type='limit', amount=trade.amount,
|
||||||
rate=closerate,
|
rate=closerate,
|
||||||
time_in_force=time_in_force,
|
time_in_force=time_in_force,
|
||||||
sell_reason=exit_.exit_reason, # deprecated
|
sell_reason=exit_reason, # deprecated
|
||||||
exit_reason=exit_.exit_reason,
|
exit_reason=exit_reason,
|
||||||
current_time=exit_candle_time):
|
current_time=exit_candle_time):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
trade.exit_reason = exit_.exit_reason
|
trade.exit_reason = exit_reason
|
||||||
|
|
||||||
# Checks and adds an exit tag, after checking that the length of the
|
|
||||||
# row has the length for an exit tag column
|
|
||||||
if(
|
|
||||||
len(row) > EXIT_TAG_IDX
|
|
||||||
and row[EXIT_TAG_IDX] is not None
|
|
||||||
and len(row[EXIT_TAG_IDX]) > 0
|
|
||||||
and exit_.exit_type in (ExitType.EXIT_SIGNAL,)
|
|
||||||
):
|
|
||||||
trade.exit_reason = row[EXIT_TAG_IDX]
|
|
||||||
|
|
||||||
self.order_id_counter += 1
|
self.order_id_counter += 1
|
||||||
order = Order(
|
order = Order(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user