Zeus_8_1d 20250714-20251007 824.533 155.858 38619

This commit is contained in:
Jérôme Delacotte
2025-10-18 11:51:23 +02:00
parent 7720646267
commit ee45dc890d
2 changed files with 337 additions and 195 deletions

View File

@@ -145,7 +145,6 @@ class Zeus_8_1d(IStrategy):
pair: {
"first_buy": 0,
"last_buy": 0.0,
"first_amount": 0.0,
"last_min": 999999999999999.5,
"last_max": 0,
"trade_info": {},
@@ -333,7 +332,7 @@ class Zeus_8_1d(IStrategy):
self.pairs[pair]['last_date'] = current_time
self.pairs[pair]['last_palier_index'] = -1
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')
@@ -366,7 +365,7 @@ class Zeus_8_1d(IStrategy):
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_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
@@ -376,8 +375,6 @@ class Zeus_8_1d(IStrategy):
baisse = 0
if profit > 0:
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
self.pairs[pair]['count_of_buys'] = count_of_buys
self.pairs[pair]['current_profit'] = profit
@@ -387,7 +384,7 @@ class Zeus_8_1d(IStrategy):
days_since_first_buy = (current_time - trade.open_date_utc).days
hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0
if True or (hours % 4 == 0):
if hours % 4 == 0:
self.log_trade(
last_candle=last_candle,
date=current_time,
@@ -403,23 +400,18 @@ class Zeus_8_1d(IStrategy):
pair_name = self.getShortName(pair)
# if baisse > 10 and max_profit > 5 and count_of_buys == 1:
# if baisse > 20 and before_last_candle[self.indicateur_achat_vente] > last_candle[self.indicateur_achat_vente] :
# self.pairs[pair]['force_sell'] = False
# return 'Bss_' + pair_name + '_' + str(count_of_buys) + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
# self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5)
# 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 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:
if last_candle['mid_smooth_5_deriv1'] <= -0.1 and profit > expected_profit and last_candle['rsi'] > 65:
self.pairs[pair]['force_sell'] = False
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))
if last_candle['mid_smooth_12_deriv1'] <= -0.1 and profit > expected_profit:
if last_candle['mid_smooth_24_deriv1'] <= -0.1 \
and profit > expected_profit:
self.pairs[pair]['force_sell'] = False
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))
@@ -456,7 +448,7 @@ class Zeus_8_1d(IStrategy):
)
self.printLineLog()
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']
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']
@@ -600,8 +592,7 @@ class Zeus_8_1d(IStrategy):
# print(metadata['pair'])
dataframe['rsi'] = talib.RSI(dataframe['close'], timeperiod=14)
dataframe['max_rsi_12'] = talib.MAX(dataframe['rsi'], timeperiod=12)
dataframe['min_rsi_12'] = talib.MIN(dataframe['rsi'], timeperiod=12)
self.calculeDerivees(dataframe, 'rsi', horizon=5)
self.calculeDerivees(dataframe, 'rsi', horizon=12)
dataframe['max12'] = talib.MAX(dataframe['close'], timeperiod=12)
dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12)
@@ -800,26 +791,23 @@ class Zeus_8_1d(IStrategy):
# (dataframe['percent'] > 0)
# & (dataframe['mid_smooth_12_deriv1'] >= dataframe['mid_smooth_12_deriv1'].shift(1))
# ), ['enter_long', 'enter_tag']] = (1, 'down')
factor = 1.01
if pair == "BTC/USDT" or pair == "BTC/USDC":
factor = factor / 2
dataframe.loc[
(
# (valid_inversion & inversion_last5 )
# (dataframe['mid_smooth_12'].shift(2) > dataframe['mid_smooth_12'].shift(1))
# (dataframe['mid_smooth_24_deriv1'].shift(1) <= 0)
(dataframe['mid_smooth_5_deriv1'] >= 0.0)
(dataframe['mid_smooth_24_deriv1'] >= 0.05)
& (dataframe['mid_smooth_24_deriv2'] > 0)
& (dataframe['mid_smooth_5_deriv2'] > 0)
# & (dataframe['hapercent'] > 0)
# & (dataframe['max_rsi_12'] < 70)
& (dataframe['open'] <= dataframe['bb_middleband'])
#& (dataframe['max_rsi_12'] < 50)
# & (dataframe['open'] <= dataframe['bb_middleband'])
), ['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)
return dataframe
@@ -897,7 +885,7 @@ class Zeus_8_1d(IStrategy):
max_stake: float, **kwargs):
# ne rien faire si ordre deja en cours
if trade.has_open_orders:
print("skip open orders")
# print("skip open orders")
return None
if (self.wallets.get_available_stake_amount() < 0): # or trade.stake_amount >= max_stake:
return 0
@@ -950,14 +938,13 @@ class Zeus_8_1d(IStrategy):
# lim = self.getLimitBuy(pair, last_candle, pct)
if (len(dataframe) < 1):
print("skip dataframe")
# print("skip dataframe")
return None
if not self.should_enter_trade(pair, last_candle, current_time):
print("enter trade not allowed")
return None
condition = (last_candle['sma5_deriv1'] > 0) or ((last_candle['min_rsi_12'] < 20) and (last_candle['hapercent'] > 0)) # and \
condition = (last_candle['sma5_deriv1'] > 0) # and \
if condition and (pct_max < lim):
try:
@@ -1003,7 +990,7 @@ class Zeus_8_1d(IStrategy):
return stake_amount
return None
except Exception as exception:
print(exception)
# print(exception)
return None
last_lost = self.getLastLost(last_candle, pair)
@@ -1082,15 +1069,16 @@ class Zeus_8_1d(IStrategy):
return val
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é
# pct60 = round(100 * self.getPctClose60D(pair, last_candle), 2)
if True: # not pair in ('BTC/USDT', 'BTC/USDC'):
# factors = [1, 1.2, 1.3, 1.4]
if self.pairs[pair]['count_of_buys'] == 0:
pctClose60 = self.getPctClose60D(pair, last_candle)
# dist_max = self.getDistMax(last_candle, pair)
factor = self.multi_step_interpolate(pctClose60, self.thresholds, self.factors)
# pctClose60 = self.getPctClose60D(pair, last_candle)
dist_max = self.getDistMax(last_candle, pair)
factor = self.multi_step_interpolate(dist_max, self.thresholds, self.factors)
adjusted_stake_amount = max(base_stake_amount / 5, base_stake_amount * factor)
else:
@@ -1123,7 +1111,7 @@ class Zeus_8_1d(IStrategy):
if pair == "BTC/USDT" or pair == "BTC/USDC":
lim = 0.005
pct = 0.001
pct_to_max = lim #+ pct * self.pairs[pair]['count_of_buys']
pct_to_max = lim + pct * self.pairs[pair]['count_of_buys']
# if self.pairs[pair]['count_of_buys'] > 6:
# pct_to_max = 0.006 * self.pairs[pair]['count_of_buys']
# pctClose60 = self.getPctClose60D(pair, last_candle)
@@ -1497,7 +1485,7 @@ class Zeus_8_1d(IStrategy):
# return False
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)
open_date = trade.open_date.astimezone(timezone.utc)
current_time_utc = current_time.astimezone(timezone.utc)