添加ema52显示
This commit is contained in:
+60
-27
@@ -21,29 +21,61 @@ from ChanMACD import ChanMACD
|
||||
from TF_DF import TF_DF
|
||||
|
||||
class ChanLun():
|
||||
time1 = 1
|
||||
time3 = 3
|
||||
time5 = 5
|
||||
time10 = 10
|
||||
time15 = 15
|
||||
time30 = 30
|
||||
time60 = 60
|
||||
time2h = 120
|
||||
time4h = 240
|
||||
time6h = 360
|
||||
time8h = 480
|
||||
time12h = 720
|
||||
time1d = 1440
|
||||
timeframes = [time1, time3, time5, time10, time15, time30, time60]
|
||||
tf_df_dict = {}
|
||||
def init_data(self, dataframe, ticker_indicator):
|
||||
for timeframe in self.timeframes:
|
||||
self.tf_df_dict[timeframe] = TF_DF(timeframe, dataframe, ticker_indicator)
|
||||
def cal_bsp(self, dataframe, ticker_indicator):
|
||||
# 初始化多周期数据
|
||||
self.init_data(dataframe, ticker_indicator)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.time3m = 3
|
||||
self.time5m = 5
|
||||
self.time10m = 10
|
||||
self.time15m = 15
|
||||
self.time30m = 30
|
||||
self.time_m_intervals = [3, 5, 10, 15, 30]
|
||||
self.time_m_symbols = ['3m', '5m', '10m', '15m', '30m']
|
||||
self.time2h = 2*60
|
||||
self.time4h = 4*60
|
||||
self.time6h = 6*60
|
||||
self.time8h = 8*60
|
||||
self.time12h = 12*60
|
||||
self.time16h = 16*60
|
||||
self.time_h_intervals = [2*60, 4*60, 6*60, 8*60, 12*60, 16*60]
|
||||
self.time_h_symbols = ['2h', '4h', '6h', '8h', '12h', '16h']
|
||||
self.time2d = 2*24*60
|
||||
self.time3d = 3*24*60
|
||||
self.time1w = 7*24*60
|
||||
self.time2w = 14*24*60
|
||||
self.time_d_intervals = [2*24*60, 3*24*60, 7*24*60, 14*24*60]
|
||||
self.time_d_symbols = ['2d', '3d', '1w', '2w']
|
||||
self.time2M = 2*30*24*60
|
||||
self.time3M = 3*30*24*60
|
||||
self.time6M = 6*30*24*60
|
||||
self.time1y = 12*30*24*60
|
||||
self.time_M_intervals = [2*30*24*60, 3*30*24*60, 6*30*24*60, 12*30*24*60]
|
||||
self.time_M_symbols = ['2M', '3M', '6M', '1y']
|
||||
self.time_symbols = ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '16h', '1d', '2d', '3d', '1w', '2w', '1M', '3M', '6M', '1y']
|
||||
self.tf_df_dict = {}
|
||||
self.ema_symbols = ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '16h', '1d', '2d', '3d', '1w', '2w']
|
||||
def init_data(self, dataframe, intervals, timeframes):
|
||||
for index in range(0, len(intervals)):
|
||||
timeframe = timeframes[index]
|
||||
interval = intervals[index]
|
||||
self.tf_df_dict[timeframe] = TF_DF(dataframe, interval, timeframe)
|
||||
def init_dataframes(self, dataframe_m, dataframe_h, dataframe_d, dataframe_M):
|
||||
self.tf_df_dict['1m'] = TF_DF(dataframe_m, 1, '1m')
|
||||
self.init_data(dataframe_m, self.time_m_intervals, self.time_m_symbols)
|
||||
self.tf_df_dict['1h'] = TF_DF(dataframe_h, 1, '1h')
|
||||
self.init_data(dataframe_h, self.time_h_intervals, self.time_h_symbols)
|
||||
self.tf_df_dict['1d'] = TF_DF(dataframe_d, 1, '1d')
|
||||
self.init_data(dataframe_d, self.time_d_intervals, self.time_d_symbols)
|
||||
self.tf_df_dict['1M'] = TF_DF(dataframe_M, 1, '1M')
|
||||
self.init_data(dataframe_M, self.time_M_intervals, self.time_M_symbols)
|
||||
def get_ema52_dict(self):
|
||||
if len(self.tf_df_dict) > 0:
|
||||
return {key: self.tf_df_dict[key].get_ema52() for key in self.ema_symbols}
|
||||
return None
|
||||
def get_ema24_dict(self):
|
||||
if len(self.tf_df_dict) > 0:
|
||||
return {key: self.tf_df_dict[key].get_ema24() for key in self.ema_symbols}
|
||||
return None
|
||||
def cal_bsp(self):
|
||||
return
|
||||
def check_fx(self, klc):
|
||||
if klc.pre and klc.next:
|
||||
if klc.high > klc.pre.high and klc.high > klc.next.high:
|
||||
@@ -444,13 +476,14 @@ class ChanLun():
|
||||
hist = getattr(klc, 'macdhist', 0) if getattr(klc, 'macdhist', None) is not None else 0
|
||||
rsi = getattr(klc, 'rsi', None)
|
||||
trend = Chan_PRICE_TREND.UNKNOWN
|
||||
score = 0
|
||||
try:
|
||||
# 有效性
|
||||
price_valid = price is not None and price != 0
|
||||
ema24_valid = ema24 is not None and ema24 != 0
|
||||
ema52_valid = ema52 is not None and ema52 != 0
|
||||
# 多因子投票
|
||||
score = 0
|
||||
|
||||
# 1) 均线结构 + 价位
|
||||
if ema24_valid and ema52_valid:
|
||||
score += 1 if ema24 > ema52 else -1
|
||||
@@ -542,9 +575,9 @@ class ChanLun():
|
||||
setattr(klc, 'trend', trend)
|
||||
last_trend = trend
|
||||
price_diff = klc.close - klc.pre.close if klc.pre else 0
|
||||
if klc.index > len(klc_list) - 10:
|
||||
print(klc.start_time, klc.end_time, klc.close, klc.ema24, klc.ema52, klc.macd, klc.signal, klc.macdhist, klc.trend, price_diff)
|
||||
#print(klc.start_time, klc.end_time, klc.trend, price_diff)
|
||||
#if klc.index > len(klc_list) - 10:
|
||||
#print(klc.start_time, klc.end_time, klc.close, klc.ema24, klc.ema52, klc.macd, klc.signal, klc.macdhist, klc.trend, price_diff, score)
|
||||
#print(klc.start_time, klc.end_time, klc.trend, price_diff, score)
|
||||
return klc_list
|
||||
def cal_bi_list(self, klc_list):
|
||||
bi_list = []
|
||||
|
||||
Reference in New Issue
Block a user