diff --git a/Zeus_8_3_2_B_4_2.py b/Zeus_8_3_2_B_4_2.py index 4c94c51..d60ad5f 100644 --- a/Zeus_8_3_2_B_4_2.py +++ b/Zeus_8_3_2_B_4_2.py @@ -155,7 +155,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): # last_candle_12 = dataframe.iloc[-13].squeeze() # allow_to_buy = True #(not self.stop_all) #& (not self.all_down) - allow_to_buy = True # (rate <= float(limit)) | (entry_tag == 'force_entry') + allow_to_buy = not last_candle['tendency'] in ('B--', 'B++') # (rate <= float(limit)) | (entry_tag == 'force_entry') self.trades = list() dispo = round(self.wallets.get_available_stake_amount()) @@ -166,7 +166,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): self.pairs[pair]['count_of_buys'] = 1 self.pairs[pair]['current_profit'] = 0 - print( + self.printLog( f"|{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 14}+{'-' * 8}+{'-' * 10}+{'-' * 7}+{'-' * 13}+{'-' * 14}+{'-' * 14}+{'-' * 7}+{'-' * 12}|" ) @@ -175,7 +175,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): self.log_trade( last_candle=last_candle, date=current_time, - action="START BUY", + action="START BUY" if allow_to_buy else "Canceled", pair=pair, rate=rate, dispo=dispo, @@ -250,8 +250,10 @@ class Zeus_8_3_2_B_4_2(IStrategy): self.pairs[pair]['current_profit'] = current_profit pct_first = round((last_candle['close'] - self.pairs[pair]['first_buy']) / self.pairs[pair]['first_buy'], 3) - # if (last_candle['tendency'] in ('H++', 'H--')): - # return None + if (last_candle['tendency'] in ('H++', 'H--')) \ + and (last_candle['tendency_1d'] in ('H++', 'H--')) \ + and (last_candle['tendency_1d'] in ('H++', 'H--')) : + return None # if (last_candle['rsi_1d'] > 50) & (last_candle['percent12'] < 0.0): if (last_candle['percent3'] < 0.0) & (current_profit > 0.05): #last_candle['min_max200'] / 3): @@ -318,11 +320,11 @@ class Zeus_8_3_2_B_4_2(IStrategy): # print( # f"|{'-' * 18}+{'-' * 12}+{'-' * 12}+{'-' * 20}+{'-' * 14}+{'-' * 8}+{'-' * 10}+{'-' * 7}+{'-' * 13}+{'-' * 14}+{'-' * 14}+{'-' * 7}+{'-' * 12}|" # ) - print( - f"| {'Date':<16} | {'Action':<10} |{'Pair':<5}| {'Trade Type':<18} | {'Rate':>12} | {'Dispo':>6} | {'Profit':>8} | {'Pct':>5} | {'max_touch':>11} | {'last_lost':>12} | {'last_max':>12} | {'Buys':>5} | {'Stake':>10} |" + self.printLog( + f"| {'Date':<16} | {'Action':<10} |{'Pair':<5}| {'Trade Type':<18} | {'Rate':>12} | {'Dispo':>6} | {'Profit':>8} | {'Pct':>6} | {'max_touch':>11} | {'last_lost':>12} | {'last_max':>12} | {'Buys':>5} | {'Stake':>10} |" ) - print( - f"|{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 14}+{'-' * 8}+{'-' * 10}+{'-' * 7}+{'-' * 13}+{'-' * 14}+{'-' * 14}+{'-' * 7}+{'-' * 12}|" + self.printLog( + f"|{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 14}+{'-' * 8}+{'-' * 10}+{'-' * 8}+{'-' * 13}+{'-' * 14}+{'-' * 14}+{'-' * 7}+{'-' * 12}|" ) self.columns_logged += 1 date = str(date)[:16] if date else "-" @@ -362,27 +364,32 @@ class Zeus_8_3_2_B_4_2(IStrategy): + " " + str(int(last_candle['rsi_1h'])) \ + " " + str(int(last_candle['rsi_diff_1h'])) - print( + self.printLog( f"| {date:<16} | {action:<10} | {pair[0:3]:<3} | {trade_type or '-':<18} | {rate or '-':>12} | {dispo or '-':>6} " - f"| {profit or '-':>8} | {pct_max or '-':>5} | {max_touch or '-':>11} | {last_lost or '-':>12} " + f"| {profit or '-':>8} | {pct_max or '-':>6} | {max_touch or '-':>11} | {last_lost or '-':>12} " f"| {round(self.pairs[pair]['last_max'], 2) or '-':>12} | {buys or '-':>5} | {stake or '-':>10} " f"| {last_candle['tendency'] or '-':>3} | {last_candle['tendency_1h'] or '-':>3} | {last_candle['tendency_1d'] or '-':>3} |" ) + def printLog(self, str): + print(str) + logger.info(str) + def add_tendency_column(self, dataframe: pd.DataFrame) -> pd.DataFrame: def tag_by_derivatives(row): d1 = row['mid_smooth_deriv1'] d2 = row['mid_smooth_deriv2'] - - if d1 == 0.0 and d2 == 0.0: + d1_lim_inf = -5 + d1_lim_sup = 5 + if d1 >= d1_lim_inf and d1 <= d1_lim_sup: # and d2 >= d2_lim_inf and d2 <= d2_lim_sup: return 'P' # Palier if d1 == 0.0: return 'DH' if d2 > 0 else 'DB' #Depart Hausse / Départ Baisse - if d1 > 0: + if d1 > d1_lim_sup: return 'H++' if d2 > 0 else 'H--' #Acceleration Hausse / Ralentissement Hausse - if d1 < 0: + if d1 < d1_lim_inf: return 'B++' if d2 < 0 else 'B--' # Accéleration Baisse / Ralentissement Baisse - return 'indetermine' + return 'Mid' dataframe['tendency'] = dataframe.apply(tag_by_derivatives, axis=1) return dataframe @@ -650,10 +657,13 @@ class Zeus_8_3_2_B_4_2(IStrategy): # 2. Calcul du lissage sur 200 bougies par moyenne mobile médiane dataframe['mid_smooth'] = dataframe['mid'].rolling(window=window, center=True, min_periods=1).median().rolling( 3).mean() + dataframe['mid_smooth_tag_max'] = (dataframe['mid_smooth'].shift(1)) == 0 & (dataframe['mid_smooth'] < 0) + dataframe['mid_smooth_tag_min'] = (dataframe['mid_smooth'].shift(1)) == 0 & (dataframe['mid_smooth'] > 0) + # 2. Dérivée première = différence entre deux bougies successives - dataframe['mid_smooth_deriv1'] = dataframe['mid_smooth'].diff() + dataframe['mid_smooth_deriv1'] = round(dataframe['mid_smooth'].diff(), 2) # 3. Dérivée seconde = différence de la dérivée première - dataframe['mid_smooth_deriv2'] = dataframe['mid_smooth_deriv1'].diff() + dataframe['mid_smooth_deriv2'] = round(dataframe['mid_smooth_deriv1'].diff(), 2) dataframe = self.add_tendency_column(dataframe) return dataframe @@ -886,7 +896,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): first_price = self.pairs[pair]['first_buy'] - last_max = current_price + last_max = last_candle['max200'] if self.pairs[pair]['last_max'] > 0: last_max = self.pairs[pair]['last_max'] last_count = self.pairs[pair]['last_count_of_buys']