diff --git a/Zeus_8_3_2_B_4_2.py b/Zeus_8_3_2_B_4_2.py index b052325..5df4df0 100644 --- a/Zeus_8_3_2_B_4_2.py +++ b/Zeus_8_3_2_B_4_2.py @@ -250,13 +250,16 @@ 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['rsi_1d'] > 50) & (last_candle['percent12'] < 0.0): if (last_candle['percent3'] < 0.0) & (current_profit > 0.05): #last_candle['min_max200'] / 3): self.trades = list() return 'mx_' + str(count_of_buys) if (last_candle['percent12'] <= -0.01) & (current_profit >= expected_profit): self.trades = list() - return 'profit_' + str(count_of_buys) + return 'pft_' + str(count_of_buys) if (current_profit >= expected_profit) & (last_candle['percent'] < 0.0) \ and ((last_candle['rsi'] >= 75) or before_last_candle['rsi'] >= 75)\ and (count_of_buys < 5): @@ -360,9 +363,30 @@ class Zeus_8_3_2_B_4_2(IStrategy): + " " + str(int(last_candle['rsi_diff_1h'])) print( - f"| {date:<16} | {action:<10} | {pair[0:3]:<3} | {trade_type or '-':<18} | {rate or '-':>12} | {dispo or '-':>6} | {profit or '-':>8} | {pct_max or '-':>5} | {max_touch or '-':>11} | {last_lost or '-':>12} | {round(self.pairs[pair]['last_max'], 2) or '-':>12} | {buys or '-':>5} | {stake or '-':>10} |" + 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"| {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 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: + return 'P' # Palier + if d1 == 0.0: + return 'DH' if d2 > 0 else 'DB' #Depart Hausse / Départ Baisse + if d1 > 0: + return 'H++' if d2 > 0 else 'H--' #Acceleration Hausse / Ralentissement Hausse + if d1 < 0: + return 'B++' if d2 < 0 else 'B--' # Accéleration Baisse / Ralentissement Baisse + return 'indetermine' + + dataframe['tendency'] = dataframe.apply(tag_by_derivatives, axis=1) + return dataframe + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Add all ta features pair = metadata['pair'] @@ -375,6 +399,8 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['close_02'] = dataframe['haclose'] * 1.02 dataframe['pct_change'] = dataframe['close'].pct_change(5) + dataframe = self.calculateTendency(dataframe) + dataframe['min'] = talib.MIN(dataframe['close'], timeperiod=200) dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12) @@ -410,6 +436,8 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['sma20_s5'] = dataframe['sma20'].shift(4) # print(metadata['pair']) dataframe['rsi'] = talib.RSI(dataframe['close'], length=14) + dataframe['rsi_diff'] = dataframe['rsi'].diff() + dataframe['rsi_diff_2'] = dataframe['rsi_diff'].diff() # Bollinger Bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) @@ -463,10 +491,12 @@ class Zeus_8_3_2_B_4_2(IStrategy): # normalized_close = self.min_max_scaling(dataframe['close']) ################### INFORMATIVE 1h informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1h") + informative = self.calculateTendency(informative) informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close'] informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close'] informative['rsi'] = talib.RSI(informative['close'], length=7) - informative['rsi_diff'] = informative['rsi'] - informative['rsi'].shift(1) + informative['rsi_diff'] = informative['rsi'].diff() + informative['rsi_diff_2'] = informative['rsi_diff'].diff() informative['sma5'] = talib.SMA(informative, timeperiod=5) informative['sma5_pct'] = 100 * (informative['sma5'] - informative['sma5'].shift(1)) / informative['sma5'] @@ -474,8 +504,11 @@ class Zeus_8_3_2_B_4_2(IStrategy): ################### INFORMATIVE 1d informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d") + informative = self.calculateTendency(informative) + informative['rsi'] = talib.RSI(informative['close'], length=7) - informative['rsi_diff'] = informative['rsi'] - informative['rsi'].shift(1) + informative['rsi_diff'] = informative['rsi'].diff() + informative['rsi_diff_2'] = informative['rsi_diff'].diff() informative['sma5'] = talib.SMA(informative, timeperiod=5) informative['sma5_pct'] = 100 * (informative['sma5'] - informative['sma5'].shift(1)) / informative['sma5'] @@ -612,6 +645,18 @@ class Zeus_8_3_2_B_4_2(IStrategy): return dataframe + def calculateTendency(self, dataframe): + dataframe['mid'] = dataframe['open'] + (dataframe['close'] - dataframe['open']) / 2 + # 2. Calcul du lissage sur 200 bougies par moyenne mobile médiane + dataframe['mid_smooth'] = dataframe['mid'].rolling(window=12, center=True, min_periods=1).median().rolling( + 3).mean() + # 2. Dérivée première = différence entre deux bougies successives + dataframe['mid_smooth_deriv1'] = dataframe['mid_smooth'].diff() + # 3. Dérivée seconde = différence de la dérivée première + dataframe['mid_smooth_deriv2'] = dataframe['mid_smooth_deriv1'].diff() + dataframe = self.add_tendency_column(dataframe) + return dataframe + def getOpenTrades(self): # if len(self.trades) == 0: print('search open trades') @@ -704,9 +749,17 @@ class Zeus_8_3_2_B_4_2(IStrategy): # (dataframe["bb_width"] > 0.01) (dataframe['down_count'].shift(1) < - 6) & (dataframe['down_count'] == 0) - # & (dataframe['down_pct'].shift(1) <= -0.5) + & (dataframe['tendency'] != "B++") + & (dataframe['tendency'] != "B--") ), ['enter_long', 'enter_tag']] = (1, 'down') + dataframe.loc[ + ( + (dataframe['low'] < dataframe['min200']) + & (dataframe['min50'] == dataframe['min200'].shift(3)) + & (dataframe['tendency'] != "B++") + & (dataframe['tendency'] != "B--") + ), ['enter_long', 'enter_tag']] = (1, 'low') dataframe['test'] = np.where(dataframe['enter_long'] == 1, dataframe['close'] * 1.01, np.nan) return dataframe @@ -777,6 +830,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): or ((last_candle['min50'] == last_candle_3['min50']) and (last_candle['low'] <= last_candle['min50'])) ) \ and (last_candle['rsi_diff_1h'] >= -5) \ + and (last_candle['tendency'] in ('P', 'H++', 'DH', 'H--')) \ and ((pct_max < lim)): try: # print(self.adjust_stake_amount(pair, last_candle))