1 Star 0 Fork 16

小鹏/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
macd.py 28.49 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2018-04-18 16:43 . no commit message
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
#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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaopengshijie/traderStock-gui.git
git@gitee.com:xiaopengshijie/traderStock-gui.git
xiaopengshijie
traderStock-gui
traderStock-gui
master

搜索帮助