def loop_one_prepare(): barlist = ['1min', '3mins', '15mins', '1hour', '1day'] ## pre prepare ES for compares startmode = 'initialize' TicksUtile.prepare_tickfilesto5secBars( today, 'ES', startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist: durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown + today + '.' + 'ES' + '.' + basisdur + '.both.csv' TicksUtile.assemble_dur_bars(today, 'ES', dur, startmode, basisfile) ############## end ES prepare for sym in symbol_list: startmode = 'initialize' TicksUtile.prepare_tickfilesto5secBars( today, sym, startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist: ## print dur, sym durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv' TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile) ## indlist = ['StochK','Stoch_CROSS','StochD','pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower',\ ## 'kmid','ema','mcross', 'mcd','diffESTXvES','RSI'] indlist = [ 'mcross', 'mcd', 'RSI', 'StochK', 'Stoch_CROSS', 'StochD', 'kupper', 'klower', 'kmid', 'diffvES' ] rpInd.create_states_files(sym, dur.replace(' ', ''), today, threshold, indlist)
def loop_one_prepare(): basisdur = '5secs' barlist = ['1min','3mins', '15mins', '1hour', '1day'] ## pre prepare ES for compares startmode = 'initialize' ## sym='ES' TicksUtile.prepare_tickfilesto5secBars(today,'ES',startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist : ## sym = 'ES' TicksUtile.assemble_dur_bars(today,'ES',dur,startmode,basisdur)
def loop_one_prepare(): basisdur = '5secs' barlist = ['1min', '3mins', '15mins', '1hour', '1day'] ## pre prepare ES for compares startmode = 'initialize' ## sym='ES' TicksUtile.prepare_tickfilesto5secBars( today, 'ES', startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist: ## sym = 'ES' TicksUtile.assemble_dur_bars(today, 'ES', dur, startmode, basisdur)
def make_states(): startmode = 'bothfile' startmode = 'initialize' for sym in symbol_list: TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths ###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode) barlist = ['1min', '3mins', '5mins', '15mins']##,'78mins'] for dur in barlist : if dur == '1min': basisdur = '5secs' else: basisdur = '1min' durinseconds = secdict[dur] basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisfile) ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS'] indlist = ['mcross','mcd','RSI','StochK','Stoch_CROSS','StochD'] rpInd.create_states_files(sym,dur,today,threshold,indlist)
def make_states(): startmode = 'bothfile' startmode = 'initialize' for sym in symbol_list: TicksUtile.prepare_tickfilesto5secBars( today, sym, startmode) ## merge the 5secddload with 5sec recents > 5sec boths ###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode) barlist = ['1min', '3mins', '5mins', '15mins'] ##,'78mins'] for dur in barlist: if dur == '1min': basisdur = '5secs' else: basisdur = '1min' durinseconds = secdict[dur] basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv' TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile) ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS'] indlist = [ 'mcross', 'mcd', 'RSI', 'StochK', 'Stoch_CROSS', 'StochD' ] rpInd.create_states_files(sym, dur, today, threshold, indlist)
def loop_one_prepare(): barlist = ['1min','3mins', '15mins', '1hour', '1day'] ## pre prepare ES for compares startmode = 'initialize' TicksUtile.prepare_tickfilesto5secBars(today,'ES',startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist : durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown +today+'.'+'ES'+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,'ES',dur,startmode,basisfile) ############## end ES prepare for sym in symbol_list: startmode = 'initialize' TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist : ## print dur, sym durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisfile) ## indlist = ['StochK','Stoch_CROSS','StochD','pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower',\ ## 'kmid','ema','mcross', 'mcd','diffESTXvES','RSI'] indlist = ['mcross','mcd','RSI','StochK','Stoch_CROSS','StochD','kupper', 'klower','kmid','diffvES'] rpInd.create_states_files(sym,dur.replace(' ',''),today,threshold,indlist)
def make_bars_just_5sec(date,startmode,symbol_list): for sym in symbol_list: TicksUtile.prepare_tickfilesto5secBars(date,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths
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 'cycle heartbeat...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'
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'
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'
########## basisfile = DataDown + date + '.' + sym + '.' + dur + '.both.csv' ### note the basis dur changed to just dur!! basisbars = rpu_rp.CsvToLines(basisfile) HAbars = TicksUtile.create_bars_from_bars(basisbars, date, sym, dur, durinseconds, 'hamode') ## print 'done creating HA bars' fileHABoth = DataDown + date + '.' + sym + '.' + dur.replace( ' ', '') + '.bothHA' + '.csv' rpu_rp.WriteArrayToCsvfile(fileHABoth, HAbars) ################################# loopmax = 505 loop = 0 while loop < loopmax: TicksUtile.prepare_tickfilesto5secBars(date, sym, 'initialize') # need to create 5secs and then each dur before proceding now = datetime.strftime(datetime.now(), spaceYtime_format) durlist = ['1min', '3mins', '5mins', '15mins', '1hour', '1day'] for dur in durlist: createOneMerge(dur, now, sym, date) dur = '5mins' run_oneloop(dur, now, sym, date) factor = 1 limitlines = 5.0 if sym == 'FDAX': limitlines = 15.0 curprice = float(TicksUtile.recenttick(sym, 'recent')) print '###### LINEFADES #### ', curprice, sym spotfiles = ['Full.', 'WBDaily.', 'Roundies.', 'AutoPivot.'] print 'range is ', limitlines, 'check for passes'
def assemble_bars(sym,barlist,mergemode,loopingflag): startmode = 'initialize' indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] indlist = ['mcross', 'mcd'] TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths for dur in barlist : durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds,startmode,basisfile) threshold = 0.0 rpInd.create_states_files(sym,dur.replace(' ',''),today,threshold,indlist) add different modes including first run mode to this then wrap into tickutiles and run with diff flags here if loop == 0 , run in firstpass mode if initialize mode, the basis file is chosen in the module print 'got to loop' while loop < loopmax: if loop == 0: for sym in symbol_list: startmode = 'initialize' TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths barlist = ['1min','3mins', '15mins', '1hour', '1day'] for dur in barlist : durinseconds = secdict[dur] basisdur = '5secs' basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds,startmode,basisfile) threshold = 0.0 indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] rpInd.create_states_files(sym,dur.replace(' ',''),today,threshold,indlist) #################################### if float(float(loop)/10) == round((loop/10),1): print 'cycle ', loop 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) ############### recentsigs =[] startmode = 'bothfile' startmode = 'initialize' for sym in symbol_list: TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths #################################### barlist = ['1min', '3mins', '5mins', '15mins'] for dur in barlist : if dur == '1min': basisdur = '5secs' pass else: basisdur = '1min' durinseconds = secdict[dur] basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds,startmode,basisfile) ## DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv') threshold = 0.0 ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','mcross'] ## indlist = ['pivot', 'mcross','mcd'] indlist = ['mcross','mcd'] rpInd.create_states_files(sym,dur,today,threshold,indlist) #################### state15 = rpInd.ShowRecentState(sym,'15mins','mcross','noboost') stateAge15 = rpInd.ShowRecentAge(sym,'15mins','mcross','noboost') ## state5 = rpInd.ShowRecentState(sym,'5mins','mcross') ## stateAge5 = rpInd.ShowRecentAge(sym,'5mins','mcross') barlist = ['1min', '3mins', '5mins', '15mins'] for dur in barlist : threshold = 0.0 ALLTriggers=[] lasttwo = [] if dur != '1min': Triggers = rpInd.Trigger_from_states(sym,dur,'mcross') lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_states(sym,'15mins','mcd') lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) ## ADJUST THE TRIGGER TO USE JUT 5MIN IN SLOWER MKTS.... ## 1 MIN CAN BE USED FOR THE FAST MKTS....OR TO EXIT A POSITION ## threshold = float(-0.20) ## maCrossNEARTriggers = rpInd.Trigger_MACross(DurBoth,sym,dur,threshold,'manearcross') ## rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', ALLTriggers) ############################ prevt = 0 numsigs = len(ALLTriggers) signum =0 prevbart_dt = now_dt prevbart_epoch = now_epoch ## 2015-08-24 17:35:05,0.0245,pos,0.0646,slopeup,kupper,USD.JPY,poscrxx,1min,118.43,118.36,118.36,5 for onesig in ALLTriggers: bart = onesig[0] action =onesig[7] 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 ## print bart_epoch, barToNow, barToPrev, bart if barToNow < recentlimit : tflag = 'nopass' ## print 'recent15 min state and age:', state15, stateAge15,sym posstate = rpInd.ShowRecentPositionState(sym) if action == 'negcrxx' and state15 == 'neg' and dur != '1min': ## print 'is a sell' tflag = 'passedtest' elif action == 'poscrxx' and state15 == 'pos' and dur != '1min': ## print 'is a buy' tflag = 'passedtest' pass elif action == 'poscrxx' and posstate == 'SELL': tflag = 'passedtest' pass elif action == 'negcrxx' and posstate == 'BUY': tflag = 'passedtest' pass else: ## print action, ' signal failed on ... ',dur,sym pass if tflag == 'passedtest': lasttick = recenttick(sym) onesig.append(barToNow) onesig.append('xx') onesig.append(lasttick) recentsigs.append(onesig) dur = '' if len(recentsigs) > 0: sigcount =0 for sig in sorted(recentsigs): sigtime = sig[0] sym = sig[6] sigtype = sig[5] ## barToPrev=sig[len(sig)-2] ## barToNow = sig[len(sig)-3] priceinsignal = float(sig[len(sig)-1]) action =sig[7] dur = sig[8] livesigid = sym+action+dur.replace(' ','') + sigtype showflag = look_for_REECNTdupe_sig(livesigid,sigtime) #'notsupress' sigcount+=1 if showflag != 'supress': indlist = ['mcross']#, 'R', 'S'] #'1hour', stateinfo = '' durstatelist = ['15mins', '1hour', '1day'] tside = 'BUY' if 'negcrxx' in action: tside = 'SELL' if tside == 'SELL': beep(soundarea+'sellStocks') else: beep(soundarea+'buyStocks') beep(soundarea+sym) print '===============' RP_Snapshot.snapshot_sym(sym) print '===============' print sym, tside, sigtype, dur, sigtime, now, priceinsignal ######## rpInd.create_lines(sym,bid) ## print symNEWSdict[sym] frsigline=[] frsigline.append(sym) frsigline.append(tside) frsigline.append(priceinsignal) frsigline.append(livesigid) frsigline.append(sigtime) 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): print barsize,sym,'number bars studied=',numberBars,numsigs,'=numsigs' print 'if i am 20 bars old in signal, start with trail stop depends on dur...shotrt dur = short age'
def runsigloop(): ############### recentsigs = [] startmode = 'bothfile' startmode = 'initialize' blist = ['5mins', '15mins'] #, '1hour'] for sym in symbol_list: ###### for dur in blist: ###### new_signaler(sym,dur) check_for_lines(sym) if sym == 'ES' and 'bla' == 'bla': ## show_bar8_range('04:00:00','7:00:00',sym,date) #asia ## show_bar8_range('09:35:00','12:25:00',sym,date) #europe show_bar8_range('16:00:10', '18:25:00', sym, date) #usa ## print ' roundies and 10pt intervals' ## then the other lines TicksUtile.prepare_tickfilesto5secBars( today, sym, startmode) ## merge the 5secddload with 5sec recents > 5sec boths #################################### ###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode) barlist = ['1min', '3mins', '5mins', '15mins'] ##,'78mins'] for dur in barlist: if dur == '1min': basisdur = '5secs' else: basisdur = '1min' durinseconds = secdict[dur] basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv' TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile) ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] ## indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS'] indlist = [ 'mcross', 'mcd', 'RSI', 'StochK', 'Stoch_CROSS', 'StochD' ] rpInd.create_states_files(sym, dur, today, threshold, indlist) #################### state15 = rpInd.ShowRecentState(sym, '15mins', 'mcross', 'noboost') stateAge15 = rpInd.ShowRecentAge(sym, '15mins', 'mcross', 'noboost') ## state5 = rpInd.ShowRecentState(sym,'5mins','mcross') ## stateAge5 = rpInd.ShowRecentAge(sym,'5mins','mcross') barlist = ['1min', '3mins', '5mins', '15mins'] for dur in barlist: ALLTriggers = [] lasttwo = [] if dur != '1111min': Triggers = rpInd.Trigger_from_states(sym, dur, 'mcross') lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_states(sym, '15mins', 'mcd') lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_statesValues( sym, dur, 'StochD', 25, 85) #def Trigger_from_statesValues(sym,dur,label,30,70): lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append(a) if dur != '1min': ## Triggers = rpInd.Trigger_from_statesValues(sym,dur,'RSI',20,80) Triggers = rpInd.Trigger_from_states(sym, dur, 'RSI') lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append( a ) ## ADJUST THE TRIGGER TO USE JUT 5MIN IN SLOWER MKTS.... ## 1 MIN CAN BE USED FOR THE FAST MKTS....OR TO EXIT A POSITION ## threshold = float(-0.20) ## maCrossNEARTriggers = rpInd.Trigger_MACross(DurBoth,sym,dur,threshold,'manearcross') ## rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', ALLTriggers) ############################ ## print ALLTriggers prevt = 0 numsigs = len(ALLTriggers) ## print numsigs signum = 0 prevbart_dt = now_dt prevbart_epoch = now_epoch ## 2015-08-24 17:35:05,0.0245,pos,0.0646,slopeup,kupper,USD.JPY,poscrxx,1min,118.43,118.36,118.36,5 for onesig in ALLTriggers: bart = onesig[0] action = onesig[7] indvalue = onesig[1] ind = onesig[5] bart_dt = dt.datetime.strptime(bart, spaceYtime_format) bart_epoch = int( time.mktime(time.strptime(bart, spaceYtime_format))) barToNow = now_epoch - bart_epoch lasttick = recenttick(sym) onesig.append(barToNow) onesig.append(indvalue) onesig.append(lasttick) if barToNow < recentlimit: ## print onesig tflag = 'nopass' ## print 'recent15 min state and age:', state15, stateAge15,sym posstate = rpInd.ShowRecentPositionState(sym) if action == 'negcrxx' and state15 == 'neg' and dur != '1min': ## print 'is a sell' tflag = 'passedtest' elif action == 'poscrxx' and state15 == 'pos' and dur != '1min': ## print 'is a buy' tflag = 'passedtest' pass elif action == 'poscrxx' and posstate == 'SELL': tflag = 'passedtest' pass elif action == 'negcrxx' and posstate == 'BUY': tflag = 'passedtest' pass elif ind == 'RSI': ## print onesig tflag = 'passedtest' pass else: ## print action, ' signal failed on ... ',dur,sym pass if tflag == 'passedtest': recentsigs.append(onesig) return recentsigs
def runsigloop(): ############### recentsigs =[] startmode = 'bothfile' startmode = 'initialize' blist = ['5mins', '15mins']#, '1hour'] for sym in symbol_list: ###### for dur in blist: ###### new_signaler(sym,dur) check_for_lines(sym) if sym == 'ES' and 'bla' == 'bla': ## show_bar8_range('04:00:00','7:00:00',sym,date) #asia ## show_bar8_range('09:35:00','12:25:00',sym,date) #europe show_bar8_range('16:00:10','18:25:00',sym,date) #usa ## print ' roundies and 10pt intervals' ## then the other lines TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths #################################### ###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode) barlist = ['1min', '3mins', '5mins', '15mins']##,'78mins'] for dur in barlist : if dur == '1min': basisdur = '5secs' else: basisdur = '1min' durinseconds = secdict[dur] basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv' TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisfile) ## indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] ## indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS'] indlist = ['mcross','mcd','RSI','StochK','Stoch_CROSS','StochD'] rpInd.create_states_files(sym,dur,today,threshold,indlist) #################### state15 = rpInd.ShowRecentState(sym,'15mins','mcross','noboost') stateAge15 = rpInd.ShowRecentAge(sym,'15mins','mcross','noboost') ## state5 = rpInd.ShowRecentState(sym,'5mins','mcross') ## stateAge5 = rpInd.ShowRecentAge(sym,'5mins','mcross') barlist = ['1min', '3mins', '5mins', '15mins'] for dur in barlist : ALLTriggers=[] lasttwo = [] if dur != '1111min': Triggers = rpInd.Trigger_from_states(sym,dur,'mcross') lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_states(sym,'15mins','mcd') lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_statesValues(sym,dur,'StochD',25,85) #def Trigger_from_statesValues(sym,dur,label,30,70): lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) if dur != '1min': ## Triggers = rpInd.Trigger_from_statesValues(sym,dur,'RSI',20,80) Triggers = rpInd.Trigger_from_states(sym,dur,'RSI') lasttwo = rpu_rp.tail_array_to_array(Triggers,1) for a in lasttwo: ALLTriggers.append(a) ## ADJUST THE TRIGGER TO USE JUT 5MIN IN SLOWER MKTS.... ## 1 MIN CAN BE USED FOR THE FAST MKTS....OR TO EXIT A POSITION ## threshold = float(-0.20) ## maCrossNEARTriggers = rpInd.Trigger_MACross(DurBoth,sym,dur,threshold,'manearcross') ## rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', ALLTriggers) ############################ ## print ALLTriggers prevt = 0 numsigs = len(ALLTriggers) ## print numsigs signum =0 prevbart_dt = now_dt prevbart_epoch = now_epoch ## 2015-08-24 17:35:05,0.0245,pos,0.0646,slopeup,kupper,USD.JPY,poscrxx,1min,118.43,118.36,118.36,5 for onesig in ALLTriggers: bart = onesig[0] action =onesig[7] indvalue = onesig[1] ind =onesig[5] bart_dt = dt.datetime.strptime(bart, spaceYtime_format) bart_epoch = int(time.mktime(time.strptime(bart, spaceYtime_format))) barToNow = now_epoch - bart_epoch lasttick = recenttick(sym) onesig.append(barToNow) onesig.append(indvalue) onesig.append(lasttick) if barToNow < recentlimit : ## print onesig tflag = 'nopass' ## print 'recent15 min state and age:', state15, stateAge15,sym posstate = rpInd.ShowRecentPositionState(sym) if action == 'negcrxx' and state15 == 'neg' and dur != '1min': ## print 'is a sell' tflag = 'passedtest' elif action == 'poscrxx' and state15 == 'pos' and dur != '1min': ## print 'is a buy' tflag = 'passedtest' pass elif action == 'poscrxx' and posstate == 'SELL': tflag = 'passedtest' pass elif action == 'negcrxx' and posstate == 'BUY': tflag = 'passedtest' pass elif ind == 'RSI': ## print onesig tflag = 'passedtest' pass else: ## print action, ' signal failed on ... ',dur,sym pass if tflag == 'passedtest': recentsigs.append(onesig) return recentsigs
TicksUtile.merge_bar_files(filerecent,fileddload,outfile,cutoffmintime) else: shutil.copyfile(fileddload,outfile) ## print 'found no ddload file so did no merge' ########## basisfile = DataDown +date+'.'+sym+'.'+dur+'.both.csv' ### note the basis dur changed to just dur!! basisbars = rpu_rp.CsvToLines(basisfile) HAbars = TicksUtile.create_bars_from_bars(basisbars,date,sym,dur,durinseconds,'hamode') ## print 'done creating HA bars' fileHABoth = DataDown +date+'.'+sym+'.'+dur.replace(' ','')+'.bothHA' +'.csv' rpu_rp.WriteArrayToCsvfile(fileHABoth,HAbars) ################################# loopmax = 505 loop = 0 while loop < loopmax: TicksUtile.prepare_tickfilesto5secBars(date,sym,'initialize') # need to create 5secs and then each dur before proceding now = datetime.strftime(datetime.now(),spaceYtime_format) durlist = ['1min','3mins','5mins','15mins','1hour','1day'] for dur in durlist: createOneMerge(dur,now,sym,date) dur = '5mins' run_oneloop(dur,now,sym,date) factor = 1 limitlines = 5.0 if sym == 'FDAX': limitlines = 15.0 curprice = float(TicksUtile.recenttick(sym,'recent')) print '###### LINEFADES #### ',curprice ,sym spotfiles = ['Full.','WBDaily.','Roundies.','AutoPivot.'] print 'range is ',limitlines, 'check for passes'