代码拉取完成,页面将自动刷新
同步操作将从 macroan/traderStock-gui 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#coding=utf-8
import talib as ta
import numpy as np
import pandas as pd
import kdj
import volume
import public
import ma
class Macd:
__instance = None
def __init__(self):
pass
@classmethod
def getInstance(cls):
if(cls.__instance == None):
cls.__instance = Macd()
return cls.__instance
def myMACD(self, price, fastperiod=12, slowperiod=26, signalperiod=9):
ewma12 = pd.ewma(price,span=fastperiod)
ewma60 = pd.ewma(price,span=slowperiod)
#ewma12 = ta.EMA(price, fastperiod)
#ewma60 = ta.EMA(price, slowperiod)
dif = ewma12-ewma60
dea = pd.ewma(dif,span=signalperiod)
bar = (dif-dea)*2
return dif, dea, bar
# 同花顺和通达信等软件中的MACD
def MACD_CN(self, close, fastperiod, slowperiod, signalperiod) :
dif, dea, macd = ta.MACDEXT(close, fastperiod=fastperiod, fastmatype=1, slowperiod=slowperiod, slowmatype=1, signalperiod=signalperiod, signalmatype=1)
macd = macd * 2
return dif, dea, macd
#设置macdgc gc:金叉 dc:死叉 R:最近的,A:历史所有
def set_macd_data(self, df, type=1):
if df is not None and df.shape[0] > 0:
dif, dea, macd = self.myMACD(np.array(df['close']), fastperiod=12, slowperiod=26, signalperiod=9)
#dif, dea, macd = self.MACD_CN(np.array(df['close']), fastperiod=12, slowperiod=26, signalperiod=9)
df['dif']=pd.Series(dif,index=df.index)#DIFF
df['dea']=pd.Series(dea,index=df.index)#DEA
df['macd']=pd.Series(macd,index=df.index)#DIFF-DEA
#计算macdgc、d_gc情况
df['macd_cross'] = ''
macd_position = df['dif'] > df['dea']
df.loc[macd_position[(macd_position == True) & (macd_position.shift() == False)].index, 'macd_cross'] = 'gc'
df.loc[macd_position[(macd_position == False) & (macd_position.shift() == True)].index, 'macd_cross'] = 'dc'
#df.dropna(how='any', inplace=True)#删除所有空行值的数据
return df
#是否是叉
def is_cross(self, df, index, crosstype='gc'):
if index < 0 or index > df.shape[0]-1:
return False
cross_ret = {'gc':df.iloc[index]['macd_cross']=='gc', 'dc':df.iloc[index]['macd_cross']=='dc'}
return cross_ret[crosstype]
#==============================================计算成功率=====================================
#macdgc平均涨幅,成功率
def macd_glodencross(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(dflen):
if df.iloc[i]['macd_cross'] == 'gc':
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macdgc放量平均涨幅,成功率
def macd_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(dflen):
if df.iloc[i]['macd_cross'] == 'gc' and v.is_fangliang(df, i):#成交量放大:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上第一次gc平均涨幅,成功率
def macd_zeroup_first_glodencross(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
target2 = 0
start = 0
flag = False
for i in xrange(0, dflen):
if start == 0 and i+2<dflen \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60']:
target = i
start = 1
continue
if start == 1:
if i - target >= 32 or df.iloc[i]['macd_cross'] == 'gc':
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 5:
#target2 = i
#if df.iloc[target]['close'] > df[target:target2]['high'].max():
flag = True
#if target2 != 0 and i-target2 < 21:
#if df.iloc[i]['dif'] > 0:
#start = 0
#target2 = 0
#flag = False
#continue
if flag:
start = 0
target2 = 0
flag = False
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上第一次gc放量平均涨幅,成功率
def macd_zeroup_first_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
if dflen < 30:
return meettotalCount, meettotal
target = 0
target2 = 0
start = 0
flag = False
for i in xrange(0, dflen):
if start == 0 and i+2<dflen \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60'] \
and v.is_fangliang(df, i):
target = i
start = 1
continue
if start == 1:
if i - target == 32 or df.iloc[i]['macd_cross'] == 'gc':
start = 0
continue
if target2==0 and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 5:
target2 = i
flag = True
if target2 != 0 and i-target2 < 21:
if df.iloc[i]['dea'] > 0:
start = 0
target2 = 0
flag = False
continue
if flag:
start = 0
target2 = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上第一次gc平均涨幅,成功率
def macd_zeroup_first_glodencross_ma_duotou(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
if dflen < 30:
return meettotalCount, meettotal
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i]['MA_5'] > df.iloc[i]['MA_10'] and df.iloc[i]['MA_10'] > df.iloc[i]['MA_30'] and df.iloc[i]['MA_30'] > df.iloc[i]['MA_60'] \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60']:
target = i
start = 1
continue
if start == 1:
if i - target == 32 or df.iloc[i]['macd_cross'] == 'gc':
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上第一次gc平均涨幅,成功率
def macd_zeroup_first_glodencross_ma_duotou_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
if dflen < 30:
return meettotalCount, meettotal
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i]['MA_5'] > df.iloc[i]['MA_10'] and df.iloc[i]['MA_10'] > df.iloc[i]['MA_30'] and df.iloc[i]['MA_30'] > df.iloc[i]['MA_60'] \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] \
and v.is_fangliang(df, i):
target = i
start = 1
continue
if start == 1:
if i - target == 32 or df.iloc[i]['macd_cross'] == 'gc':
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd dif首次突破零轴
def macd_dif_first_up_zero_succ(df):
m_a = ma.Ma.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(dflen):
if start == 0 and i+1 < dflen \
and df.iloc[i]['dif'] > 0 and df.iloc[i+1]['dif'] < 0 \
and df.iloc[i]['macd'] > 0 \
and df.iloc[i]['close'] > df.iloc[i]['MA_60']:
target = i
start = 1
continue
if start == 1:
if m_a.ma_xielv(df, target, 'dif', 'up', 5) and m_a.ma_xielv(df, target, 'MA_60', 'down', 8):
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
start = 0
return meettotalCount, meettotal
#macd dif首次突破零轴
def macd_dif_first_up_zero_volume_succ(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and i+1 < dflen \
and df.iloc[i]['dea'] > 0 and df.iloc[i+1]['dea'] < 0 \
and df.iloc[i]['macd'] > 0 \
and v.is_fangliang(df, i):
target = i
start = 1
continue
if start == 1:
if i+1 >= dflen:
break
if df.iloc[i]['dea'] < df.iloc[i+1]['dea'] or df.iloc[i]['dif'] < df.iloc[i]['dea']:
start = 0
continue
if i - target > 8:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下二次gc平均涨幅,成功率
def macd_zerodown_two_glodencross(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and df.iloc[i]['macd_cross'] == 'gc':
target = i
start = 1
continue
if start == 1:
if (i-target) == 21 or df.iloc[i]['dif'] > 0 or df.iloc[i]['dea'] > 0:
start = 0
continue
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[target]['dif'] > df.iloc[i]['dif']\
and df.iloc[target]['dea'] > df.iloc[i]['dea']:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下二次gc平均涨幅,成功率
def macd_zerodown_two_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and df.iloc[i]['macd_cross'] == 'gc':
target = i
start = 1
continue
if start == 1:
if (i-target) == 21 or df.iloc[i]['dif'] > 0 or df.iloc[i]['dea'] > 0:
target = 0
start = 0
continue
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[target]['dif'] > df.iloc[i]['dif']\
and df.iloc[target]['dea'] > df.iloc[i]['dea'] and v.is_fangliang(df, i):
target = 0
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下gc平均涨幅,成功率
def macd_zerodown_glodencross(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下gc放量平均涨幅,成功率
def macd_zerodown_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0 and \
df.iloc[i]['dea'] < 0 and v.is_fangliang(df, i): #成交量放大
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上gc平均涨幅,成功率
def macd_zeroup_glodencross(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] >= 0 and df.iloc[i]['dea'] >= 0:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴上gc放量平均涨幅,成功率
def macd_zeroup_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] >= 0 and df.iloc[i]['dea'] >= 0 and \
v.is_fangliang(df, i):#成交量放大:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd kdjgc共振
def macd_kdj_glodencross(df):
k = kdj.Kdj.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and k.is_cross(df, i, crosstype='gc'):
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd kdjgc共振放量
def macd_kdj_glodencross_volume(df):
k = kdj.Kdj.getInstance()
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and k.is_cross(df, i, crosstype='gc') \
and v.is_fangliang(df, i):#成交量放大:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0上 kdjgc共振
def macd_zeroup_kdj_glodencross(df):
k = kdj.Kdj.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] >= 0 and \
df.iloc[i]['dea'] >= 0 and k.is_cross(df, i, crosstype='gc'):
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd kdj gc共振放量
def macd_zeroup_kdj_glodencross_volume(df):
k = kdj.Kdj.getInstance()
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc'and df.iloc[i]['dif'] >= 0 and \
df.iloc[i]['dea'] >= 0 and k.is_cross(df, i, crosstype='gc') and v.is_fangliang(df, i):#成交量放大
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下 kdjgc共振
def macd_zerodown_kdj_glodencross(df):
k = kdj.Kdj.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0 and \
df.iloc[i]['dea'] < 0 and k.is_cross(df, i, crosstype='gc'):
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴下 kdjgc共振放量
def macd_zerodown_kdj_glodencross_volume(df):
k = kdj.Kdj.getInstance()
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0 and \
df.iloc[i]['dea'] < 0 and k.is_cross(df, i, crosstype='gc') and v.is_fangliang(df, i):#成交量放大:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴附近gc平均涨幅,成功率
def macd_zeronear_glodencross(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0.06 and df.iloc[i]['dif'] > -0.05:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd0轴附近gc放量平均涨幅,成功率
def macd_zeronear_glodencross_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(0, dflen):
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0.06 and \
df.iloc[i]['dif'] > -0.05 and v.is_fangliang(df, i):#成交量放大
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
return meettotalCount, meettotal
#macd高位二次gc平均涨幅,成功率
def macd_zeroup_two_glodencross(df, i, day, total):
dflen = df.shape[0]
if df.iloc[i]['dif'] > 0 and df.iloc[i]['dea'] > 0:
for j in xrange(1, 22):
if i+j < dflen:
if df.iloc[i+j]['macd_cross'] == 'gc' and df.iloc[i+j]['dif'] > 0 and df.iloc[i+j]['dea'] > 0:
total['totalCount'] += 1
if (i - day) > -1:
zf = ((df.iloc[i-day]['close'] - df.iloc[i]['close'])) / df.iloc[i]['close']*100
total['totalRate'] += zf
if df.iloc[i-day]['close'] > df.iloc[i]['close']:
total['successCount'] += 1
break
#macd高位二次gc放量平均涨幅,成功率
def macd_zeroup_two_glodencross_volume(df, i, day, total):
dflen = df.shape[0]
v = volume.Volume.getInstance()
if df.iloc[i]['dif'] > 0 and df.iloc[i]['dea'] > 0:
for j in xrange(1, 22):
if i+j < dflen:
if df.iloc[i+j]['macd_cross'] == 'gc' and df.iloc[i+j]['dif'] > 0 and df.iloc[i+j]['dea'] > 0:
if v.is_fangliang(df, i):#成交量放大
total['totalCount'] += 1
if (i - day) > -1:
zf = ((df.iloc[i-day]['close'] - df.iloc[i]['close'])) / df.iloc[i]['close']*100
total['totalRate'] += zf
if df.iloc[i-day]['close'] > df.iloc[i]['close']:
total['successCount'] += 1
break
#macd0轴附近二次gc平均涨幅,成功率
def macd_zeronear_two_glodencross(df, i, day, total):
dflen = df.shape[0]
if df.iloc[i]['dif'] < 0.06 and df.iloc[i]['dif'] > -0.05:
for j in xrange(1, 14):
if i+j < dflen:
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0.06 and df.iloc[i]['dif'] > -0.05:
total['totalCount'] += 1
if (i - day) > -1:
zf = ((df.iloc[i-day]['close'] - df.iloc[i]['close'])) / df.iloc[i]['close']*100
total['totalRate'] += zf
if df.iloc[i-day]['close'] > df.iloc[i]['close']:
total['successCount'] += 1
break
#macd0轴附近二次gc放量平均涨幅,成功率
def macd_zeronear_two_glodencross_volume(df, i, day, total):
dflen = df.shape[0]
v = volume.Volume.getInstance()
if df.iloc[i]['dif'] < 0.06 and df.iloc[i]['dif'] > -0.05:
for j in xrange(1, 14):
if i+j < dflen:
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[i]['dif'] < 0.06 and df.iloc[i]['dif'] > -0.05:
if v.is_fangliang(df, i):#成交量放大
total['totalCount'] += 1
if (i - day) > -1:
zf = ((df.iloc[i-day]['close'] - df.iloc[i]['close'])) / df.iloc[i]['close']*100
total['totalRate'] += zf
if df.iloc[i-day]['close'] > df.iloc[i]['close']:
total['successCount'] += 1
break
def macd_zeroup_redbar_decup_succ(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and i+1 < dflen \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] >= 0 \
and df.iloc[i+1]['dif'] > 0 and df.iloc[i+1]['dea'] > 0 and df.iloc[i+1]['macd'] > 0 \
and df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
target = i
start = 1
continue
if start == 1:
if i - target == 32:
start = 0
continue
if i < (target+4) and (target+4) < dflen:
if df.iloc[i]['macd'] < 0 or df.iloc[i+1]['macd'] < 0 or df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
def macd_zeroup_redbar_decup_volume_succ(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and i+1 < dflen \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i+1]['dif'] > 0 and df.iloc[i+1]['dea'] > 0 \
and df.iloc[i+1]['macd'] > 0 and df.iloc[i]['macd'] > df.iloc[i+1]['macd'] \
and v.is_fangliang(df, i):
target = i
start = 1
continue
if start == 1:
if i - target == 32:
start = 0
continue
if i < (target+4) and (target+4) < dflen:
if df.iloc[i]['macd'] < 0 or df.iloc[i+1]['macd'] < 0 or df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
def macd_zeroup_redbar_decup_ma_duotou(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and i+2 < dflen \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i+1]['dif'] > 0 and df.iloc[i+1]['dea'] > 0 and df.iloc[i+1]['macd'] > 0 and df.iloc[i]['macd'] > df.iloc[i+1]['macd'] \
and df.iloc[i]['MA_5'] > df.iloc[i]['MA_10'] and df.iloc[i]['MA_10'] > df.iloc[i]['MA_30'] and df.iloc[i]['MA_30'] > df.iloc[i]['MA_60'] \
and df.iloc[i]['MA_60'] >= df.iloc[i+1]['MA_60']:
target = i
start = 1
continue
if start == 1:
if i - target == 32:
start = 0
continue
if i < (target+4) and (target+4) < dflen:
if df.iloc[i]['macd'] < 0 or df.iloc[i+1]['macd'] < 0 or df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
def macd_zeroup_redbar_decup_ma_duotou_volume(df):
v = volume.Volume.getInstance()
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
target = 0
start = 0
for i in xrange(0, dflen):
if start == 0 and i+1 < dflen \
and df.iloc[i]['dif'] >= 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i+1]['dif'] > 0 and df.iloc[i+1]['dea'] > 0 and df.iloc[i+1]['macd'] > 0 and df.iloc[i]['macd'] > df.iloc[i+1]['macd'] \
and df.iloc[i]['MA_5'] > df.iloc[i]['MA_10'] and df.iloc[i]['MA_10'] > df.iloc[i]['MA_30'] and df.iloc[i]['MA_30'] > df.iloc[i]['MA_60'] \
and df.iloc[i]['MA_60'] >= df.iloc[i+1]['MA_60']\
and v.is_fangliang(df, i):
target = i
start = 1
continue
if start == 1:
if i - target == 32:
start = 0
continue
if i < (target+4) and (target+4) < dflen:
if df.iloc[i]['macd'] < 0 or df.iloc[i+1]['macd'] < 0 or df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
start = 0
continue
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i-target > 2:
start = 0
meettotalCount = public.compute_succ_zf(df, target, meettotalCount, meettotal)
return meettotalCount, meettotal
#=================================选股==========================================================
def macd_zeroup_first_gc(df, code):
v = volume.Volume.getInstance()
retcode = 0
flag = False
target = 0
target2 = 0
start = False
dflen = df.shape[0]
for i in xrange(dflen):
if i==0 and i+2 < dflen \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] < 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60']:
#and v.is_fangliang(df, i) \
#and df.iloc[i]['close'] > df.iloc[i]['open']:
start = True
target = i
continue
if start:
if i-target == 32 or df.iloc[i]['macd_cross'] == 'gc':
break
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i > 5:
#target2 = i
#if target2 != 0 and df[target2:target2+13][df[target2:target2+13]['dif']>0].shape[0] > 0:
#break
#if df.iloc[target]['high'] > df[1:target2]['high'].max():
flag = True
if flag:
retcode = code
break
return retcode
def macd_zeroup_first_gc_volume(df, code):
v = volume.Volume.getInstance()
retcode = 0
flag = False
target = 0
target2 = 0
start = False
dflen = df.shape[0]
for i in xrange(dflen):
if i==0 and i+2 < dflen \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] < 1.5 and df.iloc[i]['dea'] > 0 \
and (df.iloc[i]['close']-df.iloc[i+1]['close'])/df.iloc[i+1]['close'] < 0.097 \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60'] \
and v.is_fangliang(df, i):
start = True
target = i
continue
if start:
if i-target == 32 or df.iloc[i]['macd_cross'] == 'gc':
break
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i > 5:
target2 = i
flag = True
if target2 != 0 and i - target2 < 13:
if df.iloc[i]['dea'] > 0:
break
if flag:
retcode = code
break
return retcode
def macd_zeroup_redbar_decup(df, code):
retcode = 0
flag = False
dflen = df.shape[0]
start = False
target = 0
target2 = 0
for i in xrange(dflen):
if i == 0 \
and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] < 1.5 and df.iloc[i]['dea'] > 0 \
and df.iloc[i+1]['dif'] > 0 and df.iloc[i+1]['dea'] > 0 \
and df.iloc[i]['macd'] > df.iloc[i+1]['macd'] \
and (df.iloc[i]['close']-df.iloc[i+1]['close'])/df.iloc[i+1]['close'] < 0.097 \
and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60']:
start = True
target = i
continue
if start:
if i-target == 32:
break
if i < 5:
if df.iloc[i]['macd'] < 0 or df.iloc[i]['macd'] > df.iloc[i+1]['macd']:
break
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i > 5:
retcode = code
target2 = i
flag = True
if target2 != 0 and i - target2 < 13:
if df.iloc[i]['dea'] > 0:
break
if flag:
retcode = code
break
return retcode
#macd dif首次突破零轴
def macd_dif_first_up_zero(df, code):
m_a = ma.Ma.getInstance()
retcode = 0
if df.iloc[0]['dif'] > 0 and df.iloc[1]['dif'] < 0 \
and df.iloc[0]['macd'] > 0 \
and df.iloc[0]['close'] > df.iloc[0]['MA_60']:
#if m_a.ma_xielv(df, 0, 'dif', 'up', 5) and m_a.ma_xielv(df, 0, 'MA_60', 'down', 21):
retcode = code
return retcode
def macd_zeroup_beaboutto_first_gc(df, code):
retcode = 0
dflen = df.shape[0]
flag = False
for i in xrange(0, 33):
if i == 0 and df.iloc[i]['dif'] > 0 and df.iloc[i]['dif'] <= 1.5 and df.iloc[i]['dea'] > 0 and df.iloc[i]['macd'] < 0:
flag = True
continue
if flag:
if i >= dflen or df.iloc[i]['macd_cross'] == 'gc':
break
if i-1 < 5:
if df.iloc[i-1]['macd'] < df.iloc[i]['macd'] or df.iloc[i-1]['macd'] > 0:
break
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and i > 2:
retcode = code
break
return retcode
def macd_zerodown_two_gc(df, code):
dflen = df.shape[0]
retcode = 0
for i in xrange(0, 22):
if i == 0 and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0 and df.iloc[i]['macd_cross'] == 'gc':
flag = True
else:
break
if flag == True:
if i > dflen or df.iloc[i]['dif'] > 0 or df.iloc[i]['dea'] > 0:
break
if df.iloc[i]['macd_cross'] == 'gc' and df.iloc[0]['dif'] > df.iloc[i]['dif']\
and df.iloc[0]['dea'] > df.iloc[i]['dea']:
retcode = code
break
return retcode
def macd_zerodown_gc(df, code, l):
dflen = df.shape[0]
i = 0
if i < dflen and i+1 < dflen:
if df.iloc[i]['macd_cross'] == 'gc' or df.iloc[i+1]['macd_cross'] == 'gc':
if df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0:
l.append(code)
def macd_zeroup_greenbar_dec(df, code, l):
dflen = df.shape[0]
if dflen > 1:
if df.iloc[0]['dif'] > 0 and df.iloc[0]['dea'] > 0 and df.iloc[0]['macd'] > 0 and df.iloc[1]['macd'] < 0:
flag = 1
for i in xrange(0, 4):
if i < dflen and i+1 < dflen:
if df.iloc[i]['macd'] < df.iloc[i+1]['macd']:
flag = 0
break
else:
flag = 0
break
if flag == 1:
l.append(code)
#macd底背离
def macd_dbl(df, code):
retcode = 0
dflen = df.shape[0]
start = False
target1 = 0
target2 = 0
target3 = 0
target4 = 0
for i in xrange(dflen):
if i == 0 \
and df.iloc[i]['macd_cross'] == 'gc' \
and df.iloc[i]['dif'] < 0 and df.iloc[i]['dea'] < 0:
start = True
target1 = i
continue
if start:
if target2 == 0 and df.iloc[i]['macd_cross'] == 'dc':
target2 = i
continue
if df.iloc[i]['macd_cross'] == 'gc':
target3 = i
continue
if df.iloc[i]['macd_cross'] == 'dc':
target4 = i
if df[target1:target2]['close'].min() > df[target3:target4]['close'].min() \
or df[target1:target3][df[target1:target3]['dif']>0].shape[0] > 0:
break
if df[target1:target2]['dif'].min() > df[target3:target4]['dif'].min() \
or df[target1:target2]['macd'].min() > df[target3:target4]['macd'].min():
retcode = code
break
return retcode
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。