正规期货开户 QMT量化交易交易模型:通达信函数使用教程,提供源代码
X_1:=1;X_2:=MA(CLOSE,60);X_3:=MA(CLOSE,120);DRAWBAND(X_2,RGB(90,0,0),X_3,RGB(0,90,0));MA5:MA(CLOSE,5);MA10:MA(CLOSE,10);MA20:MA(CLOSE,20);MA60:MA(CLOSE,60);MA120:MA(CLOSE,120);DRAWKLINE(HIGH,OPEN,LOW,CLOSE);X_4:=REF(CLOSE,1);X_5:=IF((CLOSE-X_4)*100/X_4>=10-0.01*100/X_4,1,0);STICKLINE(X_5,OPEN,CLOSE,2,0),COLORRED;STICKLINE(X_5,HIGH,LOW,0,0),COLORRED;X_6:=IF((X_4-CLOSE)*100/X_4>=10-0.01*100/X_4,1,0);STICKLINE(X_6,OPEN,CLOSE,2,0),COLORGREEN;STICKLINE(X_6,HIGH,LOW,0,1),COLORGREEN;X_7:=IF(REF(CLOSE,1)>REF(OPEN,1) AND OPEN>REF(CLOSE,1)*1.014 AND CLOSE<OPEN*1.02,1,3);X_8:=MA(VOL,5);X_9:=MA(VOL,12);X_10:=MA(CLOSE,6);X_11:=CROSS(CLOSE,X_10);X_12:=VOL>X_8*1.2 AND VOL>X_9*1.2;X_13:=X_7>2 AND CLOSE>HIGH*0.975;X_14:=X_11 AND X_12 AND X_13;X_15:=CLOSE<=OPEN;X_16:=COUNT(X_15,5)>=4;X_17:=REF(X_16,1);X_18:=X_14 AND X_17;X_19:=VOL>=HHV(VOL,20);X_20:=VOL/REF(VOL,1)>1.5;X_21:=EMA(CLOSE,12)-EMA(CLOSE,26);X_22:=EMA(X_21,9);X_23:=2*(X_21-X_22);X_24:=REF(CLOSE>OPEN OR OPEN>CLOSE,65) AND REF(CLOSE>OPEN OR OPEN>CLOSE,116) AND REF(CLOSE>OPEN OR OPEN>CLOSE,10);X_25:=REF(X_23,1)<REF(X_23,2) AND X_23>=0 AND X_23>REF(X_23,1);X_26:=CAPITAL<6000000;X_27:=CLOSE/REF(CLOSE,1)>1.04;X_28:=REF(CLOSE<OPEN,1) AND CLOSE>OPEN;X_29:=(X_18 AND X_19 AND X_20 AND X_25 AND X_26 AND X_27 AND X_28 AND X_24)*X_1;DRAWICON(X_29,LOW*0.98,9);DRAWICON(X_29,LOW*0.99,5);N1:=42;N2:=21;N3:=89;C1:=C/REF(C,1);MX:EMA(SLOPE(C,N2)*20+C,N1),LINETHICK1,COLORBLACK;MXR:=MX/REF(MX,1);MR:=SLOPE(MX,2);MRD:=CROSS(0,MR);TMR:=BARSLAST(MRD);MRR:=REF(MX,TMR);MN3:=HHV(MRR,N3);MFD:=CROSS(MR,0);TMF:=BARSLAST(MFD);MFT:=REF(MX,TMF);ROU:=CROSS(MX,MN3)&&MX/MFT<1.25&&MX/LLV(MX,55)<1.35;TRR:=BARSLAST(ROU);DRAWTEXT(CROSS(MX,MRR)&&MX/LLV(MX,55)<1.35,MX*0.99,'有肉吃'),COLORYELLOW;DRAWTEXT(CROSS(C,MN3)&&C1>1.035,L*0.98,'大肉')&&MXR>1.004,COLORRED;STICKLINE(CROSS(MX,MRR)&&MX/LLV(MX,55)<1.35,H,L,0.1,0),COLORYELLOW;STICKLINE(ROU,O,C,3,0),COLORRED;DRAWTEXT(TRR<=5&&MRD,H,'闪正规期货开户,不好吃'),COLORGREEN;DRAWTEXT(MX/MRR>=1.55&&MXR>1.034&&CROSS(REF(MR,1),MR),H*0.98,'当心大面'),COLORGREEN;STICKLINE(MX/MRR>=1.55&&MXR>1.034&&CROSS(REF(MR,1),MR),C,O,2,0),COLORGREEN;IF(MX>MRR&&MXR>1.004,MX,DRAWNULL),LINETHICK3,COLORGREEN,COLORRED;
文章代码来自第三方库pytdx,进行了二次封装,更方便使用,源代码提供参考学习,文档可用看官网
#导入数据from tdx_data import tdx_dataimport randomdata=tdx_data()#连接通达信 data.connect() data.get_security_daily_data()
获取数据
图片
连接函数
def next_connect(self): ''' 如果默认连接不成功使用,一般不用 ''' try: print('通达信数据连接不成功,随机选择连接') n=len(self.name_list) #随机选择 random_name=self.name_list[random.randint(0,n-1)] random_port=self.port_list[random.randint(0,n-1)] random_ip=self.ip_list[random.randint(0,n-1)] self.api.connect(ip=random_ip,port=random_port) except: random_name=self.name_list[random.randint(0,n-1)] random_port=self.port_list[random.randint(0,n-1)] random_ip=self.ip_list[random.randint(0,n-1)] self.api.connect(ip=random_ip,port=random_port)
选择数据类型
#选择数据类型函数def select_data_type(self,stock='600031'): ''' 选择数据类型 ''' if stock[:3] in ['110','113','123','127','128','111','118']: return 'bond' elif stock[:3] in ['510','511','512','513','514','515','516','517','518','588','159','501']: return 'fund' else: return 'stock'调整股票代码函数
#调整股票代码函数def adjust_stock(self,stock='600031.SH'): ''' 调整代码 ''' if stock[-2:]=='SH' or stock[-2:]=='SZ' or stock[-2:]=='sh' or stock[-2:]=='sz': stock=stock.upper() else: if stock[:3] in ['600','601','603','688','510','511', '512','513','515','113','110','118','501'] or stock[:2] in ['11']: stock=stock+'.SH' else: stock=stock+'.SZ' return stock
调整市场函数
#格式化代码函数def rename_stock_type_1(self,stock='600031'): ''' 将股票类型格式化 stock股票代码 1上海 0深圳 ''' if stock[:3] in ['600','601','603','688','510','511', '512','513','515','113','110','118','501'] or stock[:2] in ['11']: marker=1 else: marker=0 return marker,stock获取实时数据函数
图片
#获取分钟数据''' 获取分钟数据 n数据类型 0 5分钟K线 1 15分钟K线 2 30分钟K线 3 1小时K线 4 日K线 5 周线 6 月线 7 1分钟 8 1分钟K线 9 年线 10 季线 marker市场0深圳1上海 stock股票代码 start开始位置 count返回的数据长度'''df3=data.get_security_minute_data(stock='600031',count=800,n=4)df3
图片
指数数据
#指数分析数据''' 获取指数数据 0 5分钟K线 1 15分钟K线 2 30分钟K线 3 1小时K线 4 日K线 5 周线 6 月线 7 1分钟 8 1分钟K线 9 年线 10 季线 index_code指数代码 marker市场类型0深圳,1上海'''df4=data.get_index_minute_data(index_code='000001',count=800,n=4)df4图片
源代码在主页介绍或si我分享正规期货开户
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。