添加新的策略

This commit is contained in:
jackyu66git
2026-02-04 22:53:52 +08:00
parent 98e309802a
commit 39b5103858
4 changed files with 451 additions and 109 deletions
+23 -4
View File
@@ -89,11 +89,15 @@ class ChanLun_EMA52(IStrategy):
# startup_candle_count = 1600
big_tf = '1h'
small_tf = '15m'
last_time = datetime.now()
last_time = None
chan = ChanLun()
last_order = None
last_trade = None
pair = 'BTC/USDT:USDT'
long_tf = '1h'
short_tf = '15m'
long_time = 60
short_time = 15
def informative_pairs(self):
return [(self.pair, "1h"),
(self.pair, "1d"),
@@ -102,16 +106,31 @@ class ChanLun_EMA52(IStrategy):
(self.pair, "1w"),
]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
if self.last_time + timedelta(minutes=1) < datetime.now():
long_df = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')
long_df['entry_long'] = self.long_entry_condition(long_df)
dataframe['rsi'] = ta.RSI(long_df, timeperiod=14)
if self.last_time is None or self.last_time + timedelta(minutes=1) < datetime.now():
self.last_time = datetime.now()
logger.info("init_dataframes----------------------------")
last_price = dataframe.iloc[-1]['close']
macdstr = str(long_df.iloc[-1]['macd']) + " " + str(long_df.iloc[-1]['macdsignal']) + " " + str(long_df.iloc[-1]['macdhist']))
date = dataframe.iloc[-1]['date']
tf_ema52_list = self.chan.check_price_ema52(last_price)
self.init_dataframes(dataframe)
logger.info("Date: " + date.strftime('%Y-%m-%d %H:%M:%S') + " Price: " + str(last_price) + " EMA52_list: " + str(tf_ema52_list))
logger.info("Date: " + date.strftime('%Y-%m-%d %H:%M:%S') + " Price: " + str(last_price) + " EMA52_list: " + str(tf_ema52_list) + " MACD: " + macdstr)
return dataframe
def long_entry_condition(self, long_df):
long_df['ema52'] = ta.EMA(long_df, timeperiod=52)
long_df['dir52'] = long_df['close'] - long_df['ema52']
long_df['ema156'] = ta.EMA(long_df, timeperiod=156)
long_df['dir156'] = long_df['close'] - long_df['ema156']
long_df_macd = ta.MACD(long_df, fast=12, slow=26, signal=9)
long_df['macdsignal'] = long_df_macd['macdsignal']
long_df['macd'] = long_df_macd['macd']
long_df['macdhist'] = long_df_macd['macdhist']
long_entry_condition = (long_df['dir52'] > 0) & (long_df['dir156'] > 0) & (long_df['macdhist'] > 0)
return long_entry_condition
def init_dataframes(self, dataframe_1m):
dataframe_15m = self.dp.get_pair_dataframe(pair=self.pair, timeframe='15m')
dataframe_1h = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')