TEST Simple

This commit is contained in:
Jérôme Delacotte
2025-10-20 20:54:24 +02:00
parent ee45dc890d
commit 4c0692426e
3 changed files with 963 additions and 20 deletions

View File

@@ -99,7 +99,7 @@ class Zeus_8_1d(IStrategy):
},
"subplots": {
"Rsi": {
"max_rsi_12": {
"max_rsi_24": {
"color": "blue"
},
},
@@ -145,6 +145,7 @@ 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": {},
@@ -405,16 +406,19 @@ class Zeus_8_1d(IStrategy):
# 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 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_5_deriv1'] <= -0.12 and profit > expected_profit and last_candle['max_rsi_24'] > 75 \
and last_candle['mid_smooth_5_deriv2'] <= -0.15 :
return str(count_of_buys) + '_' + 'RSI80_' + pair_name + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
if last_candle['mid_smooth_24_deriv1'] <= -0.1 \
and profit > expected_profit:
# if last_candle['mid_smooth_5_deriv1'] <= -0.1 and profit > expected_profit and last_candle['max_rsi_24'] > 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 str(count_of_buys) + '_' + 'RSI65_' + pair_name + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
if last_candle['mid_smooth_24_deriv1'] <= -0.1 and last_candle['mid_smooth_5_deriv1'] <= -0 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))
# self.pairs[pair]['force_buy'] = (self.pairs[pair]['count_of_buys'] - self.pairs[pair]['has_gain'] > 5)
return str(count_of_buys) + '_' + 'Drv3_' + pair_name + '_' + str(self.pairs[pair]['has_gain']) + '_' + str(round(baisse, 2))
self.pairs[pair]['max_touch'] = max(last_candle['close'], self.pairs[pair]['max_touch'])
@@ -591,8 +595,9 @@ 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)
self.calculeDerivees(dataframe, 'rsi', horizon=12)
dataframe['max_rsi_24'] = talib.MAX(dataframe['rsi'], timeperiod=24)
dataframe['min_rsi_24'] = talib.MIN(dataframe['rsi'], timeperiod=24)
self.calculeDerivees(dataframe, 'rsi', horizon=24)
dataframe['max12'] = talib.MAX(dataframe['close'], timeperiod=12)
dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12)
@@ -663,6 +668,7 @@ class Zeus_8_1d(IStrategy):
if count == 0:
dataframe['first_price'] = buy.price
self.pairs[pair]['first_buy'] = buy.price
self.pairs[pair]['first_amount'] = buy.price * buy.filled
# dataframe['close01'] = buy.price * 1.01
# Order(id=2396, trade=1019, order_id=29870026652, side=buy, filled=0.00078, price=63921.01,
@@ -674,12 +680,10 @@ class Zeus_8_1d(IStrategy):
# dataframe['mid_price'] = (dataframe['last_price'] + dataframe['first_price']) / 2
count_buys = count
# dataframe['limit'] = dataframe['last_price'] * (1 - self.baisse[count] / 100)
# dataframe['amount'] = amount
self.pairs[pair]['total_amount'] = amount
# Compter les baisses / hausses consécutives
self.calculateDownAndUp(dataframe, limit=0.0001)
# self.calculateDownAndUp(dataframe, limit=0.0001)
horizon_h = 12
dataframe['close_smooth'] = self.conditional_smoothing(dataframe['mid'].rolling(3).mean().dropna(),
@@ -701,6 +705,32 @@ class Zeus_8_1d(IStrategy):
self.calculeDerivees(dataframe, 'ema_volume', factor_1=10, factor_2=1, horizon=14)
dataframe['futur_percent_3'] = 100 * ((dataframe['sma5'].shift(-3) - dataframe['sma5']) / dataframe['sma5'])
futur_cols = ['futur_percent_3']
indic_1 = 'mid_smooth_5_deriv1'
indic_2 = 'mid_smooth_5_deriv2'
self.calculateProbabilite2Index(dataframe, futur_cols, indic_1, indic_2)
################### INFORMATIVE 1d
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d")
heikinashi = qtpylib.heikinashi(informative)
informative['haopen'] = heikinashi['open']
informative['haclose'] = heikinashi['close']
informative['hapercent'] = (informative['haclose'] - informative['haopen']) / informative['haclose']
informative = self.calculateDerivation(informative, window=5, suffixe="_5")
informative['sma5'] = talib.SMA(informative, timeperiod=5)
informative['sma20'] = talib.SMA(informative, timeperiod=20)
informative['max60'] = talib.MAX(informative['close'], timeperiod=60)
informative['min60'] = talib.MIN(informative['close'], timeperiod=60)
self.calculeDerivees(informative, 'sma5', factor_1=10, factor_2=1, horizon=5)
self.calculeDerivees(informative, 'sma20', factor_1=10, factor_2=1, horizon=20)
if self.dp.runmode.value in ('backtest'):
informative['futur_percent_3'] = 100 * (informative['close'].shift(-3) - informative['close']) / informative['close']
self.calculateProbabilite2Index(informative, futur_cols, indic_1, indic_2)
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
return dataframe
def calculeDerivees(self, dataframe, indic, factor_1=100, factor_2=10, horizon=5):
@@ -801,13 +831,20 @@ class Zeus_8_1d(IStrategy):
# (dataframe['mid_smooth_24_deriv1'].shift(1) <= 0)
(dataframe['mid_smooth_24_deriv1'] >= 0.05)
& (dataframe['mid_smooth_24_deriv2'] > 0)
& (dataframe['mid_smooth_5_deriv1'] > 0.001)
& (dataframe['mid_smooth_5_deriv2'] > 0)
# & (dataframe['hapercent'] > 0)
#& (dataframe['max_rsi_12'] < 50)
#& (dataframe['max_rsi_24'] < 50)
# & (dataframe['open'] <= dataframe['bb_middleband'])
), ['enter_long', 'enter_tag']] = (1, 'smth_12')
dataframe.loc[
(
(dataframe['min_rsi_24'] < 20)
& (dataframe['hapercent'] > 0)
), ['enter_long', 'enter_tag']] = (1, 'min_rsi_24')
dataframe['test'] = np.where(dataframe['enter_long'] == 1, dataframe['close'] * 1.01, np.nan)
return dataframe
@@ -990,12 +1027,12 @@ 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)
if (False and hours > 6 and last_candle['mid_smooth_5_deriv1'] > 0 and last_candle['mid_smooth_5_deriv2'] > 0):
if (hours > 6 and last_candle['mid_smooth_24_deriv1'] > 0.03 and last_candle['mid_smooth_5_deriv2'] > 0):
try:
stake_amount = self.pairs[pair]['first_amount'] / 4
if self.wallets.get_available_stake_amount() > stake_amount:
@@ -1074,6 +1111,7 @@ class Zeus_8_1d(IStrategy):
# 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]
# factors = [1, 1.2, 1.3, 1.4]
if self.pairs[pair]['count_of_buys'] == 0:
# pctClose60 = self.getPctClose60D(pair, last_candle)
@@ -1230,6 +1268,13 @@ class Zeus_8_1d(IStrategy):
return self.labels[i]
return self.labels[-1] # cas limite pour la borne max
def informative_pairs(self):
# get access to all pairs available in whitelist.
pairs = self.dp.current_whitelist()
informative_pairs = [(pair, '1d') for pair in pairs]
return informative_pairs
def approx_val_from_bins(self, matrice, numeric_matrice, row_label, col_label):
"""
Renvoie une approximation de la valeur à partir des labels binaires (e.g. B5, H1)
@@ -1401,7 +1446,6 @@ class Zeus_8_1d(IStrategy):
# print(pivot_mean.round(2))
def should_enter_trade(self, pair: str, last_candle, current_time) -> bool:
return True
limit = 3
@@ -1413,7 +1457,8 @@ class Zeus_8_1d(IStrategy):
# if not pair.startswith('BTC'):
dispo = round(self.wallets.get_available_stake_amount())
if self.pairs[pair]['stop'] and last_candle['mid_smooth_5_deriv1'] > -0.9 and last_candle['sma5_deriv1'] > 0 and last_candle['sma5_deriv2'] > 0:
if self.pairs[pair]['stop'] and last_candle['mid_smooth_5_deriv1_1d'] > -0.9 \
and last_candle['sma5_deriv1_1d'] > 0 and last_candle['sma5_deriv2_1d'] > 0:
self.pairs[pair]['stop'] = False
self.log_trade(
last_candle=last_candle,
@@ -1428,7 +1473,7 @@ class Zeus_8_1d(IStrategy):
stake=0
)
else:
if self.pairs[pair]['stop'] == False and (last_candle['sma5_deriv1'] < -0.2 or last_candle['sma5_deriv2'] < -3):
if self.pairs[pair]['stop'] == False and (last_candle['sma5_deriv1_1d'] < -0.2 or last_candle['sma5_deriv2_1d'] < -3):
self.pairs[pair]['stop'] = True
# if self.pairs[pair]['current_profit'] > 0:
# self.pairs[pair]['force_sell'] = True