import os
nZhangTing=0
nEarn=0
nTotalEarn=0
nBuy=0
nSell=0
strBuyDate=""
strPrebuyDate=False#准备买入
bPreSell=False
bPreBuy=False
strSellDate=""
for root,dirs,files in os.walk(r"..\\txt"):
for file in files:
strCode=os.path.join(root,file)[-10:-4]
if(strCode!="000661"):
continue
print("股票代码:"+strCode)
date1=""
nStart1=0#第一天开盘价
nEnd1=0#最后一天收盘价
nUpDay=0
nDownDay=0
nTotalDay=0
nTotalMin=999
nTotalMax=0
strMinDate=""
nOldEnd=0
nOldDeal=0
arrLine=[]
for line in open(os.path.join(root,file)):
arr=line.split(",")
if len(arr)>1:
nTotalDay=nTotalDay+1
nYear=int(line[0:4])
strDate=arr[0]
if(date1==""):
date1=arr[0]
nStart=float(arr[1])#开盘
if(nStart1==0):
nStart1=nStart
nMax=float(arr[2])#最高
nMin=float(arr[3])#最低
nEnd=float(arr[4])#收盘
nDeal=float(arr[5])#成交量
#放量跌,准备买入
if(nOldDeal>0):
if(nDeal/nOldDeal>5 and nEnd-nOldEnd<0):
strPrebuyDate=strDate
bPreBuy=True#准备买入
print("准备买入:"+strDate)
#卖出
if(bPreSell and nBuy!=0 and nEnd-nOldEnd<0 and strBuyDate!=strDate):
nSell=nEnd*100
nEarn=nSell-nBuy
nTotalEarn+=nEarn
nBuy=0
nSell=0
strBuyDate=""
bPreSell=False
print("卖出价格:"+str(nEnd))
print("卖出日期:"+strDate)
print("盈利:"+str(nEarn))
#买入
if(bPreBuy and strPrebuyDate!="" and nEnd>nStart):
nBuy=nEnd*100
strBuyDate=strDate
bPreBuy=False
bPreSell=True
strPrebuyDate=""
print("买入价格:"+str(nEnd))
print("买入日期:"+strDate)
arr=[nStart,nEnd,nMin,nMax]
arrLine.append(arr)
#涨停板
if( round(nOldEnd*1.1,2)<=nEnd):
bZhangTing=True
else:
bZhangTing=False
nOldEnd=nEnd
nOldDeal=nDeal
#print("收盘1:"+str(arrLine[len(arrLine)-2][1]))
#print("收盘2:"+str(arrLine[len(arrLine)-1][1]))
#nEnd1=arrLine[len(arrLine)-2][1]
#nZhangTing=round(nEnd1*1.1,2)
#print("涨停价:"+str(nZhangTing))
'''
if(bZhangTing):
nZhangTing=nZhangTing+1
with open("追涨.txt","a") as file1:
file1.write(strCode)
file1.write("总计盈利:"+str(nEarn)+"元")
file1.write("\n")
'''
'''
with open("追涨.txt","a") as file1:
file1.write("今日涨停股票数量:"+str(nZhangTing))
file1.write("\n")
'''
print("总盈利:"+str(nTotalEarn))
with open("放量跌马上买入.txt","a") as file1:
file1.write(strCode)
file1.write("总计盈利:"+str(nTotalEarn)+"元")
file1.write("\n")