def create_state_files(today, sym, dur, indicator): outfile = DataDown + today + '.' + sym + '.' + dur.replace( ' ', '') + '.' + indicator + 'state.csv' infile = DataDown + today + '.' + sym + '.' + dur.replace(' ', '') + '.both.csv' arrayin = rpu_rp.CsvToLines(infile) arrayout = rpInd.GetStates(arrayin, sym, indicator) rpu_rp.WriteArrayToCsvfile(outfile, arrayout)
## print sym rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) # flush the file to keep all sigs TicksUtile.prepare_tickfilesto5secBars(today,sym) ## merge the 5secddload with 5sec recents > 5sec boths #################################### rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) for barsize in barlist : timeframe = bardict[barsize] durinseconds = secdict[barsize] barsizeNtimeframe = timeframe + barsize dur = barsize TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds) DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv') indlist = ['MACROSS', 'MCDiv', 'price'] for indicator in indlist: indarr = rpInd.GetStates(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) indlist = ['klower', 'kmid', 'kupper'] for indicator in indlist: indarr = rpInd.GetKupper(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) #################### macdTriggers = rpInd.Trigger_MACD(DurBoth,sym,barsize) maCrossTriggers = rpInd.Trigger_MACross(DurBoth,sym,barsize) for a in maCrossTriggers: macdTriggers.append(a) state = 'seefile'
def create_slicendice(): #analyze prevcycledelay = 2 ######################## print 'got to loop' while loop < loopmax: if loop == 0: create_statesdaily() if (round((loop/10),-1) - loop) == 0: print 'cycle ', loop fileage = check_for_CP_change(cpfname) if fileage < 50: command = read_vars('Setting',cpfname) cycledelay = int(read_vars('CycleTime',cpfname)) recentlimit = int(read_vars('TimeLimitRecentSigs',cpfname)) print 'cycle delay changed to...',cycledelay # change to cycledelay later now = datetime.strftime(datetime.now(),spaceYtime_format) now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format))) now_dt = dt.datetime.strptime(now, spaceYtime_format) ## print 'ccreate sigs searching for sigs in last ',recentlimit ############### recentsigs =[] ## symbol_list = ['ES'] for sym in symbol_list: ## print sym rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) # flush the file to keep all sigs TicksUtile.prepare_tickfilesto5secBars(today,sym) ## merge the 5secddload with 5sec recents > 5sec boths #################################### rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) for barsize in barlist : timeframe = bardict[barsize] durinseconds = secdict[barsize] barsizeNtimeframe = timeframe + barsize dur = barsize TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds) DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv') indlist = ['MACROSS', 'MCDiv', 'price'] for indicator in indlist: indarr = rpInd.GetStates(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) indlist = ['klower', 'kmid', 'kupper'] for indicator in indlist: indarr = rpInd.GetKupper(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) #################### macdTriggers = rpInd.Trigger_MACD(DurBoth,sym,barsize) maCrossTriggers = rpInd.Trigger_MACross(DurBoth,sym,barsize) for a in maCrossTriggers: macdTriggers.append(a) state = 'seefile' ## sigbart = ((lline[0])[0]) ## sigbart_epoch = int(time.mktime(time.strptime(sigbart, spaceYtime_format))) ## barage = str(round((now_epoch - sigbart_epoch)/int(durinseconds),2)) barage = 'need barage' rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', macdTriggers) ############################ prevt = 0 numsigs = len(macdTriggers) signum =0 prevbart_dt = now_dt prevbart_epoch = now_epoch for l in macdTriggers: bart = l[0] bart_dt = dt.datetime.strptime(bart, spaceYtime_format) bart_epoch = int(time.mktime(time.strptime(bart, spaceYtime_format))) barToNow = now_epoch - bart_epoch barToPrev = bart_epoch - prevbart_epoch prevbart_epoch = bart_epoch if barToNow < recentlimit: onesig = l sym =onesig[1] lasttick = recenttick(sym) onesig.append(barToNow) onesig.append(barToPrev) onesig.append(lasttick) recentsigs.append(onesig) dur = '' if len(recentsigs) > 0: ## macrossstate = statefile = sigarea +statename +'.MACROSS.state.csv' sigcount =0 for sig in sorted(recentsigs): sigtime = sig[0] sym = sig[1] sigtype = sig[5] barToPrev=sig[len(sig)-2] barToNow = sig[len(sig)-3] bid = sig[len(sig)-1] action =sig[5] dur = sig[2] livesigid = sym+action+dur.replace(' ','') showflag = look_for_dupe_sig(livesigid) sigcount+=1 ## if sigcount == len(recentsigs): if showflag != 'supress': indlist = ['MACROSS']#, 'R', 'S'] ## indlist = ['MACROSS', 'MCDiv', 'price', 'kupper', 'kmid', 'klower', 'pivot', 'R', 'S'] durstatelist =['1hour', '15mins' ] ## durstatelist =['1hour', '15mins', '3mins'] stateinfo = '' for durstate in durstatelist: stateinfo += durstate #+ '\n' for indicator in indlist: sfile = rpu_rp.CsvToLines(statearea +sym+'.' + durstate +'.'+ indicator +'.state.csv') hline = (rpu_rp.tail_array_to_array(sfile,1))[0] stateinfo += str(hline[1:4])+'\n' ############################## tside = 'BUY' if 'negcrs' in action: tside = 'SELL' if tside == 'SELL': beep(soundarea+'sellStocks') else: beep(soundarea+'buyStocks') beep(soundarea+sym) priceinsignal = float(sig[3]/1) pricedrift = round(priceinsignal - float(bid),4) timedrift = barToNow print '===============' print sym, tside, sigtype, dur, pricedrift, sigtime, now create_lines(sym,bid) ## print symNEWSdict[sym] ## print timedrift,sym, tside,dur, priceinsignal,barToPrev,sigtime,pricedrift,now print stateinfo ###################### ttype = 'LIM' limitprice = bid tfactor = float(0.5) tsize = int(max(1,(int(tsizedict[sym]) * tfactor))) tickvalue = float(tickvaluedict[sym]) showdecimal = int(showdecimaldict[sym]) addamt = tickvalue * int(entrywiderdict[sym]) frsigline=[] frsigline.append(sym) frsigline.append(showdecimal) frsigline.append(tside) frsigline.append(tsize) frsigline.append(ttype) frsigline.append(limitprice) frsigline.append(addamt) frsigline.append(livesigid) frsigline.append(sigtime) frsigline.append(tickvalue) frsigline.append(now) rpu_rp.WriteArrayToCsvfileAppend(sigarea + today +'.recentsigs.csv', [frsigline]) rpu_rp.WriteArrayToCsvfileAppend(sigarea + today +'.recentsigsexec.csv', [frsigline]) loop +=1 #################### sleep(cycledelay) print 'finished ',loopmax,' loops by Signal Creator...dead since..',now ############# def create_report(Sigfile,sym,barsize): barfile = DataDown + today + '.'+sym+ '.'+ barsize +'both.csv' lines = rpu_rp.CsvToLines(barfile) numberBars = len(lines) siglines = rpu_rp.CsvToLines(Sigfile) numsigs = len(siglines) print barsize,sym,'number bars studied=',numberBars,numsigs,'=numsigs'