This commit is contained in:
Jérôme Delacotte
2025-10-13 21:38:37 +02:00
parent aabfce79ec
commit a061a9d941

View File

@@ -145,6 +145,7 @@ class Zeus_8_1d(IStrategy):
pair: { pair: {
"first_buy": 0, "first_buy": 0,
"last_buy": 0.0, "last_buy": 0.0,
"first_amount": 0.0,
"last_min": 999999999999999.5, "last_min": 999999999999999.5,
"last_max": 0, "last_max": 0,
"trade_info": {}, "trade_info": {},
@@ -332,7 +333,7 @@ class Zeus_8_1d(IStrategy):
self.pairs[pair]['last_date'] = current_time self.pairs[pair]['last_date'] = current_time
self.pairs[pair]['last_palier_index'] = -1 self.pairs[pair]['last_palier_index'] = -1
self.pairs[pair]['last_trade'] = trade self.pairs[pair]['last_trade'] = trade
self.pairs[pair]['current_trade'] = None # self.pairs[pair]['current_trade'] = None
return (allow_to_sell) | (exit_reason == 'force_exit') return (allow_to_sell) | (exit_reason == 'force_exit')
@@ -365,7 +366,7 @@ class Zeus_8_1d(IStrategy):
max_touch_before = self.pairs[pair]['max_touch'] max_touch_before = self.pairs[pair]['max_touch']
self.pairs[pair]['last_max'] = max(last_candle['close'], self.pairs[pair]['last_max']) self.pairs[pair]['last_max'] = max(last_candle['close'], self.pairs[pair]['last_max'])
self.pairs[pair]['last_min'] = min(last_candle['close'], self.pairs[pair]['last_min']) self.pairs[pair]['last_min'] = min(last_candle['close'], self.pairs[pair]['last_min'])
self.pairs[pair]['current_trade'] = trade # self.pairs[pair]['current_trade'] = trade
count_of_buys = trade.nr_of_successful_entries count_of_buys = trade.nr_of_successful_entries
@@ -375,6 +376,8 @@ class Zeus_8_1d(IStrategy):
baisse = 0 baisse = 0
if profit > 0: if profit > 0:
baisse = 100 * abs(max_profit - profit) / max_profit baisse = 100 * abs(max_profit - profit) / max_profit
# print(f"{current_time} max_profit={self.pairs[pair]['max_profit']} profit={profit} baisse={round(baisse,2)}")
mx = max_profit / 5 mx = max_profit / 5
self.pairs[pair]['count_of_buys'] = count_of_buys self.pairs[pair]['count_of_buys'] = count_of_buys
self.pairs[pair]['current_profit'] = profit self.pairs[pair]['current_profit'] = profit
@@ -384,7 +387,7 @@ class Zeus_8_1d(IStrategy):
days_since_first_buy = (current_time - trade.open_date_utc).days days_since_first_buy = (current_time - trade.open_date_utc).days
hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0 hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0
if hours % 4 == 0: if True or (hours % 4 == 0):
self.log_trade( self.log_trade(
last_candle=last_candle, last_candle=last_candle,
date=current_time, date=current_time,
@@ -400,18 +403,21 @@ class Zeus_8_1d(IStrategy):
pair_name = self.getShortName(pair) pair_name = self.getShortName(pair)
# if baisse > 20 and before_last_candle[self.indicateur_achat_vente] > last_candle[self.indicateur_achat_vente] : # if baisse > 10 and max_profit > 5 and count_of_buys == 1:
# self.pairs[pair]['force_sell'] = False # self.pairs[pair]['force_sell'] = False
# self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5) # return 'Bss_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
# return 'Baisse_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
if last_candle['mid_smooth_5_deriv1'] <= -0.1 and profit > expected_profit and last_candle['rsi'] > 65: if last_candle['mid_smooth_5_deriv1'] <= 0.1 \
and before_last_candle['mid_smooth_5_deriv2'] > 0 \
and last_candle['mid_smooth_5_deriv2'] < 0 \
and last_candle['mid_smooth_24_deriv1'] < 0.25 \
and profit > expected_profit \
and last_candle['max_rsi_12'] > 70:
self.pairs[pair]['force_sell'] = False self.pairs[pair]['force_sell'] = False
self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5) self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5)
return 'RSI_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2)) return 'RSI_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
if last_candle['mid_smooth_24_deriv1'] <= -0.1 \ if last_candle['mid_smooth_12_deriv1'] <= -0.1 and profit > expected_profit:
and profit > expected_profit:
self.pairs[pair]['force_sell'] = False self.pairs[pair]['force_sell'] = False
self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5) self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5)
return 'Drv3_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2)) return 'Drv3_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
@@ -448,7 +454,7 @@ class Zeus_8_1d(IStrategy):
) )
self.printLineLog() self.printLineLog()
df = pd.DataFrame.from_dict(self.pairs, orient='index') df = pd.DataFrame.from_dict(self.pairs, orient='index')
colonnes_a_exclure = ['last_candle', 'last_trade', 'last_palier_index', 'current_trade', colonnes_a_exclure = ['last_candle', 'last_trade', 'last_palier_index', # 'current_trade',
'trade_info', 'last_date', 'expected_profit', 'last_count_of_buys', 'base_stake_amount', 'stop_buy'] 'trade_info', 'last_date', 'expected_profit', 'last_count_of_buys', 'base_stake_amount', 'stop_buy']
df_filtered = df[df['count_of_buys'] > 0].drop(columns=colonnes_a_exclure) df_filtered = df[df['count_of_buys'] > 0].drop(columns=colonnes_a_exclure)
# df_filtered = df_filtered["first_buy", "last_max", "max_touch", "last_sell","last_buy", 'count_of_buys', 'current_profit'] # df_filtered = df_filtered["first_buy", "last_max", "max_touch", "last_sell","last_buy", 'count_of_buys', 'current_profit']
@@ -596,7 +602,8 @@ class Zeus_8_1d(IStrategy):
# print(metadata['pair']) # print(metadata['pair'])
dataframe['rsi'] = talib.RSI(dataframe['close'], timeperiod=14) dataframe['rsi'] = talib.RSI(dataframe['close'], timeperiod=14)
dataframe['max_rsi_12'] = talib.MAX(dataframe['rsi'], timeperiod=12) dataframe['max_rsi_12'] = talib.MAX(dataframe['rsi'], timeperiod=12)
self.calculeDerivees(dataframe, 'rsi', horizon=12) dataframe['min_rsi_12'] = talib.MIN(dataframe['rsi'], timeperiod=12)
self.calculeDerivees(dataframe, 'rsi', horizon=5)
dataframe['max12'] = talib.MAX(dataframe['close'], timeperiod=12) dataframe['max12'] = talib.MAX(dataframe['close'], timeperiod=12)
dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12) dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12)
@@ -794,23 +801,26 @@ class Zeus_8_1d(IStrategy):
# (dataframe['percent'] > 0) # (dataframe['percent'] > 0)
# & (dataframe['mid_smooth_12_deriv1'] >= dataframe['mid_smooth_12_deriv1'].shift(1)) # & (dataframe['mid_smooth_12_deriv1'] >= dataframe['mid_smooth_12_deriv1'].shift(1))
# ), ['enter_long', 'enter_tag']] = (1, 'down') # ), ['enter_long', 'enter_tag']] = (1, 'down')
factor = 1.01
if pair == "BTC/USDT" or pair == "BTC/USDC":
factor = factor / 2
dataframe.loc[ dataframe.loc[
( (
# (valid_inversion & inversion_last5 ) # (valid_inversion & inversion_last5 )
# (dataframe['mid_smooth_12'].shift(2) > dataframe['mid_smooth_12'].shift(1)) # (dataframe['mid_smooth_12'].shift(2) > dataframe['mid_smooth_12'].shift(1))
# (dataframe['mid_smooth_24_deriv1'].shift(1) <= 0) # (dataframe['mid_smooth_24_deriv1'].shift(1) <= 0)
(dataframe['mid_smooth_24_deriv1'] >= 0.05) (dataframe['mid_smooth_5_deriv1'] >= 0.0)
& (dataframe['mid_smooth_24_deriv2'] > 0)
& (dataframe['mid_smooth_5_deriv2'] > 0) & (dataframe['mid_smooth_5_deriv2'] > 0)
# & (dataframe['hapercent'] > 0) # & (dataframe['hapercent'] > 0)
#& (dataframe['max_rsi_12'] < 50) # & (dataframe['max_rsi_12'] < 70)
# & (dataframe['open'] <= dataframe['bb_middleband']) & (dataframe['open'] <= dataframe['bb_middleband'])
), ['enter_long', 'enter_tag']] = (1, 'smth_12') ), ['enter_long', 'enter_tag']] = (1, 'smth_12')
dataframe.loc[
(
(dataframe['min_rsi_12'] < 20)
& (dataframe['hapercent'] > 0)
), ['enter_long', 'enter_tag']] = (1, 'min_rsi_12')
dataframe['test'] = np.where(dataframe['enter_long'] == 1, dataframe['close'] * 1.01, np.nan) dataframe['test'] = np.where(dataframe['enter_long'] == 1, dataframe['close'] * 1.01, np.nan)
return dataframe return dataframe
@@ -888,7 +898,7 @@ class Zeus_8_1d(IStrategy):
max_stake: float, **kwargs): max_stake: float, **kwargs):
# ne rien faire si ordre deja en cours # ne rien faire si ordre deja en cours
if trade.has_open_orders: if trade.has_open_orders:
# print("skip open orders") print("skip open orders")
return None return None
if (self.wallets.get_available_stake_amount() < 0): # or trade.stake_amount >= max_stake: if (self.wallets.get_available_stake_amount() < 0): # or trade.stake_amount >= max_stake:
return 0 return 0
@@ -941,13 +951,14 @@ class Zeus_8_1d(IStrategy):
# lim = self.getLimitBuy(pair, last_candle, pct) # lim = self.getLimitBuy(pair, last_candle, pct)
if (len(dataframe) < 1): if (len(dataframe) < 1):
# print("skip dataframe") print("skip dataframe")
return None return None
if not self.should_enter_trade(pair, last_candle, current_time): if not self.should_enter_trade(pair, last_candle, current_time):
print("enter trade not allowed")
return None return None
condition = (last_candle['sma5_deriv1'] > 0) # and \ condition = (last_candle['sma5_deriv1'] > 0) or ((last_candle['min_rsi_12'] < 20) and (last_candle['hapercent'] > 0)) # and \
if condition and (pct_max < lim): if condition and (pct_max < lim):
try: try:
@@ -993,12 +1004,12 @@ class Zeus_8_1d(IStrategy):
return stake_amount return stake_amount
return None return None
except Exception as exception: except Exception as exception:
# print(exception) print(exception)
return None return None
last_lost = self.getLastLost(last_candle, pair) last_lost = self.getLastLost(last_candle, pair)
if (False and hours > 6 and last_candle['mid_smooth_5_deriv1'] > 0): if (hours > 6 and last_candle['mid_smooth_24_deriv1'] > 0.1):
try: try:
stake_amount = self.pairs[pair]['first_amount'] / 4 stake_amount = self.pairs[pair]['first_amount'] / 4
if self.wallets.get_available_stake_amount() > stake_amount: if self.wallets.get_available_stake_amount() > stake_amount:
@@ -1072,16 +1083,15 @@ class Zeus_8_1d(IStrategy):
return val return val
def adjust_stake_amount(self, pair: str, last_candle: DataFrame): def adjust_stake_amount(self, pair: str, last_candle: DataFrame):
# Calculer le minimum des 14 derniers jours
base_stake_amount = self.config.get('stake_amount') # Montant de base configuré base_stake_amount = self.config.get('stake_amount') # Montant de base configuré
# pct60 = round(100 * self.getPctClose60D(pair, last_candle), 2) # pct60 = round(100 * self.getPctClose60D(pair, last_candle), 2)
if True: # not pair in ('BTC/USDT', 'BTC/USDC'): if True: # not pair in ('BTC/USDT', 'BTC/USDC'):
# factors = [1, 1.2, 1.3, 1.4] # factors = [1, 1.2, 1.3, 1.4]
if self.pairs[pair]['count_of_buys'] == 0: if self.pairs[pair]['count_of_buys'] == 0:
# pctClose60 = self.getPctClose60D(pair, last_candle) pctClose60 = self.getPctClose60D(pair, last_candle)
dist_max = self.getDistMax(last_candle, pair) # dist_max = self.getDistMax(last_candle, pair)
factor = self.multi_step_interpolate(dist_max, self.thresholds, self.factors) factor = self.multi_step_interpolate(pctClose60, self.thresholds, self.factors)
adjusted_stake_amount = max(base_stake_amount / 5, base_stake_amount * factor) adjusted_stake_amount = max(base_stake_amount / 5, base_stake_amount * factor)
else: else:
@@ -1488,7 +1498,7 @@ class Zeus_8_1d(IStrategy):
# return False # return False
if (max_pair != '') & (self.pairs[pair]['count_of_buys'] >= limit): if (max_pair != '') & (self.pairs[pair]['count_of_buys'] >= limit):
trade = self.pairs[max_pair]['current_trade'] # trade = self.pairs[max_pair]['current_trade']
current_time = current_time.astimezone(timezone.utc) current_time = current_time.astimezone(timezone.utc)
open_date = trade.open_date.astimezone(timezone.utc) open_date = trade.open_date.astimezone(timezone.utc)
current_time_utc = current_time.astimezone(timezone.utc) current_time_utc = current_time.astimezone(timezone.utc)