add dynamic trade expiration time
This commit is contained in:
parent
a541943edf
commit
d6ed8f1980
@ -244,7 +244,7 @@ class FreqaiDataKitchen:
|
|||||||
self.data["filter_drop_index_training"] = drop_index
|
self.data["filter_drop_index_training"] = drop_index
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if len(self.data['constant_features_list']):
|
if len(self.data.get('constant_features_list', [])):
|
||||||
filtered_df = self.check_pred_labels(filtered_df)
|
filtered_df = self.check_pred_labels(filtered_df)
|
||||||
# we are backtesting so we need to preserve row number to send back to strategy,
|
# we are backtesting so we need to preserve row number to send back to strategy,
|
||||||
# so now we use do_predict to avoid any prediction based on a NaN
|
# so now we use do_predict to avoid any prediction based on a NaN
|
||||||
|
@ -208,12 +208,16 @@ class FreqaiBinaryClassStrategy_v4(IStrategy):
|
|||||||
stoploss = -0.05
|
stoploss = -0.05
|
||||||
use_exit_signal = True
|
use_exit_signal = True
|
||||||
startup_candle_count: int = 300
|
startup_candle_count: int = 300
|
||||||
can_short = True
|
can_short = False
|
||||||
|
|
||||||
linear_roi_offset = DecimalParameter(
|
linear_roi_offset = DecimalParameter(
|
||||||
0.00, 0.02, default=0.005, space="sell", optimize=False, load=True
|
0.00, 0.02, default=0.005, space="sell", optimize=False, load=True
|
||||||
)
|
)
|
||||||
max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True)
|
# max roi time long in minutes
|
||||||
|
# max_roi_time_long = IntParameter(0, 800, default=341, space="sell", optimize=True, load=True) # BTC
|
||||||
|
max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=True, load=False)
|
||||||
|
entry_thr = DecimalParameter(0.5, 1.0, default=0.7, space="buy", optimize=True, load=False)
|
||||||
|
exit_thr = DecimalParameter(0.5, 1.0, default=0.7, space="sell", optimize=True, load=False)
|
||||||
|
|
||||||
def informative_pairs(self):
|
def informative_pairs(self):
|
||||||
whitelist_pairs = self.dp.current_whitelist()
|
whitelist_pairs = self.dp.current_whitelist()
|
||||||
@ -360,7 +364,7 @@ class FreqaiBinaryClassStrategy_v4(IStrategy):
|
|||||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||||
hours_candle_stability = 4
|
hours_candle_stability = 4
|
||||||
if df["do_predict"].rolling(12 * hours_candle_stability).sum().iloc[-1] == 12 * hours_candle_stability: # enter the market if last `hours_candle_stability` are stable
|
if df["do_predict"].rolling(12 * hours_candle_stability).sum().iloc[-1] == 12 * hours_candle_stability: # enter the market if last `hours_candle_stability` are stable
|
||||||
enter_long_conditions = [df["do_predict"] == 1, df["min"] >= self.minima_threhsold]
|
enter_long_conditions = [df["do_predict"] == 1, df["min"] >= self.entry_thr.value]
|
||||||
|
|
||||||
if enter_long_conditions:
|
if enter_long_conditions:
|
||||||
df.loc[
|
df.loc[
|
||||||
@ -368,7 +372,7 @@ class FreqaiBinaryClassStrategy_v4(IStrategy):
|
|||||||
] = (1, "long")
|
] = (1, "long")
|
||||||
|
|
||||||
if self.can_short:
|
if self.can_short:
|
||||||
enter_short_conditions = [df["do_predict"] == 1, df["max"] >= self.maxima_threhsold]
|
enter_short_conditions = [df["do_predict"] == 1, df["max"] >= self.exit_thr.value]
|
||||||
|
|
||||||
if enter_short_conditions:
|
if enter_short_conditions:
|
||||||
df.loc[
|
df.loc[
|
||||||
@ -379,13 +383,13 @@ class FreqaiBinaryClassStrategy_v4(IStrategy):
|
|||||||
return df
|
return df
|
||||||
|
|
||||||
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||||
exit_long_conditions = [df["do_predict"] == 1, df["max"] >= self.maxima_threhsold]
|
exit_long_conditions = [df["do_predict"] == 1, df["max"] >= self.exit_thr.value]
|
||||||
if exit_long_conditions:
|
if exit_long_conditions:
|
||||||
df.loc[reduce(lambda x, y: x & y, exit_long_conditions),
|
df.loc[reduce(lambda x, y: x & y, exit_long_conditions),
|
||||||
["exit_long", "exit_tag"]] = (1, "exit signal")
|
["exit_long", "exit_tag"]] = (1, "exit signal")
|
||||||
|
|
||||||
if self.can_short:
|
if self.can_short:
|
||||||
exit_short_conditions = [df["do_predict"] == 1, df["min"] >= self.minima_threhsold]
|
exit_short_conditions = [df["do_predict"] == 1, df["min"] >= self.entry_thr.value]
|
||||||
if exit_short_conditions:
|
if exit_short_conditions:
|
||||||
df.loc[reduce(lambda x, y: x & y, exit_short_conditions), "exit_short"] = 1
|
df.loc[reduce(lambda x, y: x & y, exit_short_conditions), "exit_short"] = 1
|
||||||
return df
|
return df
|
||||||
@ -409,7 +413,9 @@ class FreqaiBinaryClassStrategy_v4(IStrategy):
|
|||||||
if dataframe["do_predict"].iloc[-1] != 1:
|
if dataframe["do_predict"].iloc[-1] != 1:
|
||||||
return f"OOD_{trade.enter_tag}_Exit"
|
return f"OOD_{trade.enter_tag}_Exit"
|
||||||
|
|
||||||
if (current_time - trade.open_date_utc).seconds > self.max_roi_time_long.value * 60:
|
time_alpha = (1 + current_profit / (self.minimal_roi[0] - self.stoploss))
|
||||||
|
time_alpha = 1.
|
||||||
|
if (current_time - trade.open_date_utc).seconds > (self.max_roi_time_long.value * 60 * time_alpha):
|
||||||
return f"{trade.enter_tag}_Expired"
|
return f"{trade.enter_tag}_Expired"
|
||||||
|
|
||||||
def confirm_trade_exit(
|
def confirm_trade_exit(
|
||||||
|
Loading…
Reference in New Issue
Block a user