按照缠论原著判断分型
This commit is contained in:
@@ -136,16 +136,20 @@ class TF_DF():
|
|||||||
return klu_state_list
|
return klu_state_list
|
||||||
def check_fx(self, klc):
|
def check_fx(self, klc):
|
||||||
if klc.pre and klc.next:
|
if klc.pre and klc.next:
|
||||||
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low and klc.macd > 0:
|
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low:
|
||||||
#if (klc.close > klc.ema52 or klc.next.close > klc.next.ema52) and klc.macd > 0:
|
if klc.pre.pre and klc.next.next:
|
||||||
klc.set_fx(Chan_FX_TYPE.TOP)
|
if klc.high > klc.pre.pre.high and klc.high > klc.next.next.high:
|
||||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "TOP")
|
#if (klc.close > klc.ema52 or klc.next.close > klc.next.ema52) and klc.macd > 0:
|
||||||
return Chan_FX_TYPE.TOP
|
klc.set_fx(Chan_FX_TYPE.TOP)
|
||||||
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high and klc.macd < 0:
|
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "TOP")
|
||||||
#if (klc.close < klc.ema52 or klc.next.close < klc.next.ema52) and klc.macd < 0:
|
return Chan_FX_TYPE.TOP
|
||||||
klc.set_fx(Chan_FX_TYPE.BOTTOM)
|
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high:
|
||||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "BOTTOM")
|
if klc.pre.pre and klc.next.next:
|
||||||
return Chan_FX_TYPE.BOTTOM
|
if klc.low < klc.pre.pre.low and klc.low < klc.next.next.low:
|
||||||
|
#if (klc.close < klc.ema52 or klc.next.close < klc.next.ema52) and klc.macd < 0:
|
||||||
|
klc.set_fx(Chan_FX_TYPE.BOTTOM)
|
||||||
|
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "BOTTOM")
|
||||||
|
return Chan_FX_TYPE.BOTTOM
|
||||||
return Chan_FX_TYPE.UNKNOWN
|
return Chan_FX_TYPE.UNKNOWN
|
||||||
def check_fx_pattern(self, klc):
|
def check_fx_pattern(self, klc):
|
||||||
klu_list = klc.pre.klu_list + klc.klu_list + klc.next.klu_list
|
klu_list = klc.pre.klu_list + klc.klu_list + klc.next.klu_list
|
||||||
|
|||||||
+24
-12
@@ -106,31 +106,37 @@ class ChanLun_EMA52(IStrategy):
|
|||||||
(self.pair, "1w"),
|
(self.pair, "1w"),
|
||||||
]
|
]
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
dataframe = self.add_indicators(dataframe)
|
||||||
long_df = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')
|
long_df = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')
|
||||||
|
long_df = self.add_indicators(long_df)
|
||||||
long_df['entry_long'] = self.long_entry_condition(long_df)
|
long_df['entry_long'] = self.long_entry_condition(long_df)
|
||||||
dataframe['rsi'] = ta.RSI(long_df, timeperiod=14)
|
dataframe['rsi'] = ta.RSI(long_df, timeperiod=14)
|
||||||
if self.last_time is None or self.last_time + timedelta(minutes=1) < datetime.now():
|
if self.last_time is None or self.last_time + timedelta(minutes=1) < datetime.now():
|
||||||
self.last_time = datetime.now()
|
self.last_time = datetime.now()
|
||||||
logger.info("init_dataframes----------------------------")
|
logger.info("init_dataframes----------------------------")
|
||||||
last_price = dataframe.iloc[-1]['close']
|
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']))
|
macdstr = str(long_df.iloc[-1]['macd']) + " " + str(long_df.iloc[-1]['macdsignal']) + " " + str(long_df.iloc[-1]['macdhist'])
|
||||||
date = dataframe.iloc[-1]['date']
|
date = dataframe.iloc[-1]['date']
|
||||||
tf_ema52_list = self.chan.check_price_ema52(last_price)
|
tf_ema52_list = self.chan.check_price_ema52(last_price)
|
||||||
self.init_dataframes(dataframe)
|
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) + " MACD: " + macdstr)
|
logger.info("Date: " + date.strftime('%Y-%m-%d %H:%M:%S') + " Price: " + str(last_price) + " EMA52_list: " + str(tf_ema52_list) + " MACD: " + macdstr)
|
||||||
|
dataframe = resampled_merge(dataframe, long_df)
|
||||||
|
print(dataframe.iloc[-1])
|
||||||
return dataframe
|
return dataframe
|
||||||
def long_entry_condition(self, long_df):
|
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)
|
long_entry_condition = (long_df['dir52'] > 0) & (long_df['dir156'] > 0) & (long_df['macdhist'] > 0)
|
||||||
return long_entry_condition
|
return long_entry_condition
|
||||||
|
def add_indicators(self, dataframe):
|
||||||
|
dataframe['ema52'] = ta.EMA(dataframe, timeperiod=52)
|
||||||
|
dataframe['dir52'] = dataframe['close'] - dataframe['ema52']
|
||||||
|
dataframe['ema156'] = ta.EMA(dataframe, timeperiod=156)
|
||||||
|
dataframe['dir156'] = dataframe['close'] - dataframe['ema156']
|
||||||
|
dataframe['dir52_156'] = dataframe['dir52'] - dataframe['dir156']
|
||||||
|
dataframe_macd = ta.MACD(dataframe, fast=12, slow=26, signal=9)
|
||||||
|
dataframe['macdsignal'] = dataframe_macd['macdsignal']
|
||||||
|
dataframe['macd'] = dataframe_macd['macd']
|
||||||
|
dataframe['macdhist'] = dataframe_macd['macdhist']
|
||||||
|
return dataframe
|
||||||
def init_dataframes(self, dataframe_1m):
|
def init_dataframes(self, dataframe_1m):
|
||||||
dataframe_15m = self.dp.get_pair_dataframe(pair=self.pair, timeframe='15m')
|
dataframe_15m = self.dp.get_pair_dataframe(pair=self.pair, timeframe='15m')
|
||||||
dataframe_1h = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')
|
dataframe_1h = self.dp.get_pair_dataframe(pair=self.pair, timeframe='1h')
|
||||||
@@ -176,12 +182,18 @@ class ChanLun_EMA52(IStrategy):
|
|||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(dataframe['rsi'] < 30),
|
(dataframe['rsi'] < 30) &
|
||||||
|
(dataframe['dir156'] > 0) &
|
||||||
|
(dataframe['dir52_156'] > 0) &
|
||||||
|
(dataframe['macdhist'] > 0),
|
||||||
'enter_long'] = 1
|
'enter_long'] = 1
|
||||||
return dataframe
|
return dataframe
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(dataframe['rsi'] > 70),
|
(dataframe['rsi'] > 70) &
|
||||||
|
(dataframe['dir156'] < 0) &
|
||||||
|
(dataframe['dir52_156'] < 0) &
|
||||||
|
(dataframe['macdhist'] < 0),
|
||||||
'exit_long'] = 1
|
'exit_long'] = 1
|
||||||
return dataframe
|
return dataframe
|
||||||
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
||||||
|
|||||||
Reference in New Issue
Block a user