def tur20(qx): ''' 海龟策略:tur10 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 tur20 是按,策略指定的数目 购买股票 默认参数示例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] x9 = qx.xbarWrk['xhigh'][0] x1 = qx.xbarWrk['xlow'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) knum0 = qx.staVars[2] #策略指定的数目,购买股票 if dprice > x9: if dnum0 == 0: #stknum = int(dcash*0.9 /dprice);#dsum=stknum*kprice stknum = knum0 elif (dprice < x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def SMA20_sta(qx): ''' 简单均线策略分析函数 每次买90%的资金 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') xnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] # ksma = 'ma_%d' % qx.staVars[1] dsma = qx.xbarWrk[ksma][0] # if (dprice > dsma) and (xnum == 0): stknum = int(dcash * qx.stkKCash / dprice) #print('buy',xtim,dprice,dsma,xnum); if (dprice <= dsma) and (xnum > 0): stknum = -1 #print('sell',xtim,dprice,dsma,xnum); # return stknum
def macd10(qx): ''' MACD策略01 MACD称为指数平滑异同平均线 当 macd>0,买入; 当 macd<0,卖出 默认参数示例: qx.staVars=[12,26,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] xk = qx.xbarWrk['macd'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) if xk > 0: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk < 0): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def rsi10(qx): ''' RSI策略 RSI相对强弱指标 当 rsi>kbuy,一般是70,80,买入 当 rsi<sell,一般是30,20,卖出 默认参数示例: qx.staVars=[14,70,30,'2015-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) # d=qx.staVars[0];kstr1='rsi_{n}'.format(n=d) xk=qx.xbarWrk[kstr1][0] kbuy,ksell=qx.staVars[1],qx.staVars[2] if xk>kbuy: if dnum0==0: stknum = int(dcash*qx.stkKCash /dprice);#dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif xk<ksell: #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def macd20(qx): ''' MACD策略02 MACD称为指数平滑异同平均线 当 macd>macd_sign,买入; 当 macd<macd_sign0,卖出 默认参数示例: qx.staVars=[12,26,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; xk=qx.xbarWrk['macd'][0]; x2=qx.xbarWrk['msign'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) if xk>x2: if dnum0==0: stknum = int(dcash*qx.stkKCash /dprice);#dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk<x2): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def SMA_sta(qx): ''' 簡單均線策略分析函數 每次買100股 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') xnum = zwx.xusrStkNum(qx, xcod) # ksma = 'ma_%d' % qx.staVars[1] dsma = qx.xbarWrk[ksma][0] # if (dprice > dsma) and (xnum == 0): stknum = 100 #print('buy',xtim,dprice,dsma,xnum); if (dprice <= dsma) and (xnum > 0): stknum = -1 #print('sell',xtim,dprice,dsma,xnum); # return stknum
def VWAP_sta(qx): ''' vwap 成交量加权平均价策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,0.01,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode # vwap=zwx.stkGetPrice(qx,'vwap') if vwap>0: dprice=zwx.stkGetVars(qx,'close') kvwap=qx.staVars[1]; xnum=zwx.xusrStkNum(qx,xcod); dcash=qx.qxUsr['cash']; dval = xnum * dprice; #---- if (dprice>vwap*(1+kvwap))and(dval<(dcash*qx.stkKCash)): stknum=100; if (dprice<vwap*(1-kvwap))and(dval>0): stknum=-100; # if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass; return stknum
def CMA_sta(qx): ''' 均线交叉策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[30,'2014-01-01',''] ''' stknum=0; xcod=qx.stkCode; dprice=zwx.stkGetPrice(qx,'dprice') dcash=qx.qxUsr['cash']; #duncash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) #---- kmod=zwx.cross_Mod(qx) # if kmod==1: if dnum0==0: stknum=int(dcash*qx.stkKCash/dprice); elif kmod==-1: stknum=-1; # if stknum!=0: #print(qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(kmod,qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(' ',stknum,dcash,qx.stkKCash,dprice) pass; return stknum
def SMA_sta(qx): ''' 简单均线策略分析函数 每次买100股 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=zwx.stkGetPrice(qx,'dprice') xnum=zwx.xusrStkNum(qx,xcod); # ksma='ma_%d' %qx.staVars[1] dsma=qx.xbarWrk[ksma][0] # if (dprice>dsma)and(xnum==0): stknum=100; #print('buy',xtim,dprice,dsma,xnum); if (dprice<=dsma)and(xnum>0): stknum=-1; #print('sell',xtim,dprice,dsma,xnum); # return stknum
def macd20(qx): ''' MACD策略02 MACD稱為指數平滑異同平均線 當 macd>macd_sign,買入; 當 macd<macd_sign0,賣出 預設參數範例: qx.staVars=[12,26,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] xk = qx.xbarWrk['macd'][0] x2 = qx.xbarWrk['msign'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) if xk > x2: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk < x2): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def tur10(qx): ''' 海龜策略:deal_stock_num 當今天的收盤價,大於過去n個交易日中的最高價時,以收盤價買入; 買入後,當收盤價小於過去n個交易日中的最低價時,以收盤價賣出。 deal_stock_num 是按資金總額的90% 購買股票 預設參數範例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] x9 = qx.xbarWrk['xhigh'][0] x1 = qx.xbarWrk['xlow'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) if dprice > x9: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (dprice < x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def tur20(qx): ''' 海龜策略:deal_stock_num 當今天的收盤價,大於過去n個交易日中的最高價時,以收盤價買入; 買入後,當收盤價小於過去n個交易日中的最低價時,以收盤價賣出。 tur20 是按,策略指定的數目 購買股票 預設參數範例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] x9 = qx.xbarWrk['xhigh'][0] x1 = qx.xbarWrk['xlow'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) knum0 = qx.staVars[2] #策略指定的數目,購買股票 if dprice > x9: if dnum0 == 0: #stknum = int(dcash*0.9 /dprice);#dsum=stknum*kprice stknum = knum0 elif (dprice < x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def VWAP_sta(qx): ''' vwap 成交量加權平均價策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[5,0.01,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode # vwap = zwx.stkGetPrice(qx, 'vwap') if vwap > 0: dprice = zwx.stkGetVars(qx, 'close') kvwap = qx.staVars[1] xnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] dval = xnum * dprice #---- if (dprice > vwap * (1 + kvwap)) and (dval < (dcash * qx.stkKCash)): stknum = 100 if (dprice < vwap * (1 - kvwap)) and (dval > 0): stknum = -100 # if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass return stknum
def CMA_sta(qx): ''' 均線交叉策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[30,'2014-01-01',''] ''' stknum = 0 xcod = qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') dcash = qx.qxUsr['cash'] #duncash=qx.qxUsr['cash']; dnum0 = zwx.xusrStkNum(qx, xcod) #---- kmod = zwx.cross_Mod(qx) # if kmod == 1: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) elif kmod == -1: stknum = -1 # if stknum != 0: #print(qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(kmod,qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(' ',stknum,dcash,qx.stkKCash,dprice) pass return stknum
def tur10(qx): ''' 海龟策略:tur10 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] x9 = qx.xbarWrk['xhigh'][0] x1 = qx.xbarWrk['xlow'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) if dprice > x9: if dnum0 == 0: stknum = int(dcash * 0.9 / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (dprice < x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def tur10(qx): ''' 海龟策略:tur10 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 tur10 是按资金总额的90% 购买股票 默认参数示例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; x9=qx.xbarWrk['xhigh'][0]; x1=qx.xbarWrk['xlow'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) if dprice>x9: if dnum0==0: stknum = int(dcash*qx.stkKCash /dprice);#dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (dprice<x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def tur20(qx): ''' 海龟策略:deal_stock_num 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 tur20 是按,策略指定的数目 购买股票 默认参数示例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; x9=qx.xbarWrk['xhigh'][0]; x1=qx.xbarWrk['xlow'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) knum0=qx.staVars[2] #策略指定的数目,购买股票 if dprice>x9: if dnum0==0: #stknum = int(dcash*0.9 /dprice);#dsum=stknum*kprice stknum = knum0 elif (dprice<x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def tur10(qx): ''' 海龟策略:deal_stock_num 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 deal_stock_num 是按资金总额的90% 购买股票 默认参数示例: qx.staVars=[5,5,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; x9=qx.xbarWrk['xhigh'][0]; x1=qx.xbarWrk['xlow'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) if dprice>x9: if dnum0==0: stknum = int(dcash*qx.stkKCash /dprice);#dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (dprice<x1): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def BBANDS_sta(qx): ''' 布林帶策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[40,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dup = zwx.stkGetVars(qx, 'boll_up') dlow = zwx.stkGetVars(qx, 'boll_low') #print(xtim,stknum,'xd',xcod,dup,dlow) if dup > 0: dprice = zwx.stkGetPrice(qx, 'dprice') kprice = zwx.stkGetPrice(qx, 'kprice') dnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] #print(xtim,stknum,dnum,'xd',dcash,dprice,'b,%.2f,%.2f' %(dlow,dup)) if (dnum == 0) and (dprice < dlow): stknum = int(dcash / dprice * qx.stkKCash) dsum = stknum * kprice if qx.debugMod > 0: print( xtim, stknum, dnum, '++,%.2f,%.2f,%.2f,$,%.2f,%.2f' % (dprice, dlow, dup, kprice, dsum)) elif (dnum > 0) and (dprice > dup): stknum = -1 dsum = dnum * kprice if qx.debugMod > 0: print( xtim, stknum, dnum, '--,%.2f,%.2f,%.2f,$,%.2f,%.2f' % (dprice, dlow, dup, kprice, dsum)) # if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass return stknum
def kdj20(qx): ''' KDJ策略20 KDJ 指標,又稱隨機指標 當 stok>stod,並且朝上,買入; 當 stok>stod,並且朝下,賣出 預設參數範例: qx.staVars=[9,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) # ksgn1, ksgn2 = 'stok', 'stod' xk, xk2 = qx.xbarWrk[ksgn1][0], qx.xbarWrk[ksgn2][0] nksgn1, nksgn2 = 'stok1n', 'stod1n' nxk, nxk2 = qx.xbarWrk[nksgn1][0], qx.xbarWrk[nksgn2][0] if (xk > xk2) and (nxk <= nxk2): if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk < xk2) and (nxk >= nxk2): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum
def tur10(qx): ''' 策略说明 Args: qx (zwQuantX): zwQuantX数据包 ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode; dprice=zwx.stkGetVars(qx,'dprice') xnum=zwx.xusrStkNum(qx,xcod); # ksma='ma_%d' %qx.staVars[1] dsma=qx.xbarWrk[ksma][0] # if (dprice>dsma)and(xnum==0): stknum=10; print('buy',xtim,dprice,dsma,xnum); if (dprice<=dsma)and(xnum>0): stknum=-1; print('sell',xtim,dprice,dsma,xnum); # return stknum
def kdj20(qx): ''' KDJ策略20 KDJ 指标,又称随机指标 当 stok>stod,并且朝上,买入; 当 stok>stod,并且朝下,卖出 默认参数示例: qx.staVars=[9,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=qx.xbarWrk['dprice'][0]; dcash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) # ksgn1,ksgn2='stok','stod' xk,xk2=qx.xbarWrk[ksgn1][0],qx.xbarWrk[ksgn2][0]; nksgn1,nksgn2='stok1n','stod1n' nxk,nxk2=qx.xbarWrk[nksgn1][0],qx.xbarWrk[nksgn2][0]; if (xk>xk2)and(nxk<=nxk2): if dnum0==0: stknum = int(dcash*qx.stkKCash /dprice);#dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk<xk2)and(nxk>=nxk2): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass; return stknum
def BBANDS_sta(qx): ''' 布林带策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[40,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dup=zwx.stkGetVars(qx,'boll_up') dlow=zwx.stkGetVars(qx,'boll_low') #print(xtim,stknum,'xd',xcod,dup,dlow) if dup>0: dprice=zwx.stkGetPrice(qx,'dprice') kprice=zwx.stkGetPrice(qx,'kprice') dnum=zwx.xusrStkNum(qx,xcod) dcash=qx.qxUsr['cash']; #print(xtim,stknum,dnum,'xd',dcash,dprice,'b,%.2f,%.2f' %(dlow,dup)) if (dnum==0)and(dprice<dlow): stknum = int(dcash /dprice*qx.stkKCash);dsum=stknum*kprice if qx.debugMod>0: print(xtim,stknum,dnum,'++,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) elif (dnum>0)and(dprice>dup): stknum = -1;dsum=dnum*kprice if qx.debugMod>0: print(xtim,stknum,dnum,'--,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) # if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass; return stknum
def kdj10(qx): ''' KDJ策略10 KDJ 指标,又称随机指标 当 stok>90,买入; 当 stok<10,卖出 默认参数示例: qx.staVars=[9,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = qx.xbarWrk['dprice'][0] dcash = qx.qxUsr['cash'] dnum0 = zwx.xusrStkNum(qx, xcod) # ksgn1, ksgn2 = 'stok', 'stod' xk, xk2 = qx.xbarWrk[ksgn1][0], qx.xbarWrk[ksgn2][0] if xk > 90: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) #dsum=stknum*kprice #stknum = 500 #print(xtim,stknum,dnum,'++b,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) #print(xtim,stknum,'++xd',xcod,dprice,x9,x1) elif (xk < 10): #stknum = -500 stknum = -1 #stknum = -1;dsum=dnum*kprice if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,x9,x1) pass return stknum