def process_ticks(lines, decimalboost): ################ bs = rpInd.strip1float(lines, 5, decimalboost) ##raw close price bshighs = rpInd.strip1float(lines, 3, decimalboost) bslows = rpInd.strip1float(lines, 4, decimalboost) timestamparray = rpInd.strip1string(lines, 1) lenbs = len(bs) tailstart = lenbs - 50 print tailstart, 'tailstart' ######################## ## sma21 = rpInd.mvavgToArray(bs,21) ## sma9 = rpInd.mvavgToArray(bs,9) ## ema21 = rpInd.EMAmvavgToArray(bs,21) ## ema9 = rpInd.EMAmvavgToArray(bs,9) ## sma50 = rpInd.EMAmvavgToArray(bs,50) ## sma12 = rpInd.EMAmvavgToArray(bs,12) ## ################ MACD ########## ## macddiff = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs,12),rpInd.EMAmvavgToArray(bs,26))## macd is the mvavg9 on this diff ## macdavg = rpInd.EMAmvavgToArray(macddiff,9) ## macddiverg = rpInd.difftwoarrays(macddiff,macdavg) ########## RSI ####### ## RSIgain = rpInd.RSIGainLoss(bs,'gain') ## RSIloss = rpInd.RSIGainLoss(bs,'loss') ## rsiavggain = rpInd.RSImvavgToArray(RSIgain,14) ## rsiavgloss = rpInd.RSImvavgToArray(RSIloss,14) ## RSratios = rpInd.ratiotwoarrays(rsiavggain,rsiavgloss) ## rsi = 100 - ( 100 / (1 + RS)) ## rsiArray =[] ## for ratio in RSratios: ## rsi = min(100,(100 - ( 100 / (1 + ratio)))) ## rsiArray.append(rsi) ################# ## tenkan = rpInd.TenkanSenmvavgToArray(bs,bshighs,bslows,9) ## kijunSen = rpInd.TenkanSenmvavgToArray(bs,bshighs,bslows,26) ## diff = rpInd.difftwoarrays(tenkan,kijunSen) ####################### ## MA9CROSS21 = rpInd.difftwoarrays(sma9,sma21) ###################### signbs = rpInd.show_sign(bs, 'price') slopebs = rpInd.show_slope(bs, 'price') ## signmcd = rpInd.show_sign(macddiverg,'mcd') ## crossesmcd = rpInd.show_crossover(signmcd,'mcd') ## slopemcd = rpInd.show_slope(macddiverg,'macddiverg') ##### MA Cross ## macrossval = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs, 9), rpInd.EMAmvavgToArray(bs, 21)) signmcd = rpInd.show_sign(macrossval, 'mcd') crossesmcd = rpInd.show_crossover(signmcd, 'mcd') slopemcd = rpInd.show_slope(macrossval, 'mcd') print len(signmcd), len(macrossval), len(crossesmcd) MDarray = rpInd.makearrayJust2(timestamparray, slopebs, signbs, bs, macrossval, crossesmcd, signmcd) ## macdcrosses = rpInd.show_macd_low_lines(MDarray,'Slope','Slope',3,.001,4)#(arrayin,texttosell,texttobuy,pricefnum,macdtestval,macdfnum) ma = rpu_rp.grep_array_to_array(MDarray, 'cross') rpInd.format_lines(ma, 5) #tailamount
def process_ticks(lines,decimalboost): ################ bs = rpInd.strip1float(lines,5,decimalboost) ##raw close price bshighs = rpInd.strip1float(lines,3,decimalboost) bslows = rpInd.strip1float(lines,4,decimalboost) timestamparray = rpInd.strip1string(lines,1) lenbs = len(bs) tailstart = lenbs - 50 print tailstart,'tailstart' ######################## ## sma21 = rpInd.mvavgToArray(bs,21) ## sma9 = rpInd.mvavgToArray(bs,9) ## ema21 = rpInd.EMAmvavgToArray(bs,21) ## ema9 = rpInd.EMAmvavgToArray(bs,9) ## sma50 = rpInd.EMAmvavgToArray(bs,50) ## sma12 = rpInd.EMAmvavgToArray(bs,12) ## ################ MACD ########## ## macddiff = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs,12),rpInd.EMAmvavgToArray(bs,26))## macd is the mvavg9 on this diff ## macdavg = rpInd.EMAmvavgToArray(macddiff,9) ## macddiverg = rpInd.difftwoarrays(macddiff,macdavg) ########## RSI ####### ## RSIgain = rpInd.RSIGainLoss(bs,'gain') ## RSIloss = rpInd.RSIGainLoss(bs,'loss') ## rsiavggain = rpInd.RSImvavgToArray(RSIgain,14) ## rsiavgloss = rpInd.RSImvavgToArray(RSIloss,14) ## RSratios = rpInd.ratiotwoarrays(rsiavggain,rsiavgloss) ## rsi = 100 - ( 100 / (1 + RS)) ## rsiArray =[] ## for ratio in RSratios: ## rsi = min(100,(100 - ( 100 / (1 + ratio)))) ## rsiArray.append(rsi) ################# ## tenkan = rpInd.TenkanSenmvavgToArray(bs,bshighs,bslows,9) ## kijunSen = rpInd.TenkanSenmvavgToArray(bs,bshighs,bslows,26) ## diff = rpInd.difftwoarrays(tenkan,kijunSen) ####################### ## MA9CROSS21 = rpInd.difftwoarrays(sma9,sma21) ###################### signbs = rpInd.show_sign(bs,'price') slopebs = rpInd.show_slope(bs,'price') ## signmcd = rpInd.show_sign(macddiverg,'mcd') ## crossesmcd = rpInd.show_crossover(signmcd,'mcd') ## slopemcd = rpInd.show_slope(macddiverg,'macddiverg') ##### MA Cross ## macrossval = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs,9),rpInd.EMAmvavgToArray(bs,21)) signmcd = rpInd.show_sign(macrossval,'mcd') crossesmcd = rpInd.show_crossover(signmcd,'mcd') slopemcd = rpInd.show_slope(macrossval,'mcd') print len(signmcd),len(macrossval),len(crossesmcd) MDarray = rpInd.makearrayJust2(timestamparray,slopebs,signbs,bs,macrossval,crossesmcd,signmcd) ## macdcrosses = rpInd.show_macd_low_lines(MDarray,'Slope','Slope',3,.001,4)#(arrayin,texttosell,texttobuy,pricefnum,macdtestval,macdfnum) ma = rpu_rp.grep_array_to_array(MDarray,'cross') rpInd.format_lines(ma,5) #tailamount
else: decimalboost = 1000 ################ bs = rpInd.strip1value(lines, 5) ##raw close price bsshort = bs[0:100] bshighs = rpInd.strip1value(lines, 3) bslows = rpInd.strip1value(lines, 4) timestamparray = rpInd.strip1value(lines, 1) ######################## sma26 = rpInd.EMAmvavgToArray(bs, 26) sma12 = rpInd.EMAmvavgToArray(bs, 12) diffs = rpInd.difftwoarrays(sma12, sma26) ## macd is the mvavg9 on this diff macdavg = rpInd.EMAmvavgToArray(diffs, 9) macddiverg = rpInd.difftwoarrays(diffs, macdavg) datearray = rpInd.strip1string(lines, 1) testlevel = float(10) RSIgain = rpInd.RSIGainLoss(bs, 'gain') RSIloss = rpInd.RSIGainLoss(bs, 'loss') rsiavggain = rpInd.RSImvavgToArray(RSIgain, 14) rsiavgloss = rpInd.RSImvavgToArray(RSIloss, 14) RS = rpInd.ratiotwoarrays(rsiavggain, rsiavgloss) ## rsi = 100 - ( 100 / (1 + RS)) rsiArray = [] for ratio in RS: rsi = min(100, (100 - (100 / (1 + ratio)))) rsiArray.append(rsi) #################
def process_ticks(lines,decimalboost,dur): ################ bs = rpInd.strip1float(lines,5,decimalboost) ##raw close price bshighs = rpInd.strip1float(lines,3,decimalboost) bslows = rpInd.strip1float(lines,4,decimalboost) timestamparray = rpInd.strip1string(lines,1) symarray = rpInd.strip1string(lines,0) sym = symarray[1] durarray = [] for b in symarray: durarray.append(dur) lenbs = len(bs) tailstart = lenbs - 50 ## print tailstart,'tailstart' ######################## ## sma21 = rpInd.mvavgToArray(bs,21) ###################### ### create pivots rs and ss ### ## def pivotpoint(a1,a2,a3): ## c=0 ## arrayout =[] ## arrayout.append(a1[0]) ## while c < len(a1): ## c+=1 ## piv = a1[c-1] + a2[c-1] + a3[c-1] ## arrayout.append(piv) ## return arrayout ###################### ## piv = pivotpoint(bs,bshighs,bslows) ## ###################### ## def R1(a1,a2): ## S1 is the same but with lows ## c=0 ## arrayout =[] ## arrayout.append(a1[0]) ## while c < len(a1): #a1 is pivotpoint array ## c+=1 ## S1 = (2*a1[c]) - a2[c-1]#prevhiarray ## arrayout.append(S1) ## return arrayout ###################### ## R1 = R1(piv,bshighs) #### ppoint = (prevbarHi + prevbarlo +prevclose)/3 ######################################## signbs = rpInd.show_sign(bs,'price') slopebs = rpInd.show_slope(bs,'price') ##### MA Cross ## macrossval = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs,9),rpInd.EMAmvavgToArray(bs,21)) signmcd = rpInd.show_sign(macrossval,'mcd') crossesmcd = rpInd.show_crossover(signmcd,'mcd') slopemcd = rpInd.show_slope(macrossval,'mcd') MDarray = rpInd.makearrayJust2(timestamparray,symarray,durarray,bs,macrossval,crossesmcd,signmcd) ma = rpu_rp.grep_array_to_array(MDarray,'cross') rpu_rp.WriteArrayToCsvfileAppend(sym+'.sigs.csv', ma) ## recents = rpu_rp.grep_array_to_array(ma,'0') ############################## from datetime import datetime current_time = datetime.now()## timenow = float(current_time.isoformat().replace(':','')) prevt = 0 numsigs = len(ma) signum =0 timex = current_time.isoformat() import datetime as dt time_format = "%H:%M:%S" now = datetime.strftime(current_time,time_format) now_dt = dt.datetime.strptime(now, time_format) prevbart_dt = now_dt for l in ma: signum +=1 if len(l[0].split()) == 2: ## time = l[0].split()[1].replace(':','') currentbar = l[0].split()[1] else: currentbar = (l[0].split()[0]) htime_format = '%H' currentbar_dt = dt.datetime.strptime(currentbar, time_format) hour = dt.datetime.strftime(currentbar_dt, htime_format) now_dt = dt.datetime.strptime(now, time_format) barToNow = (now_dt - currentbar_dt).seconds barToPrev = (currentbar_dt - prevbart_dt).seconds alerttxt = l[1] + '|' + str(barToNow) + '|' + str(barToPrev)+ '|' +str(l) prevbart_dt = currentbar_dt ## print signum,numsigs,barToNow ##['21:52:21', 'USD.JPY', '30 secs', 125.6075, 0.00011005009737630189, 'poscrossmcd', 'posposmcd' if barToNow < 20 and signum == numsigs: rpu_rp.WriteArrayToCsvfile('sigs.csv',ma) ## Mbox('Trade Alert', alerttxt, 1) rpInd.format_lines(ma,1) #tailamount
else: decimalboost = 1000 ################ bs = rpInd.strip1value(lines,5) ##raw close price bsshort = bs[0:100] bshighs = rpInd.strip1value(lines,3) bslows = rpInd.strip1value(lines,4) timestamparray = rpInd.strip1value(lines,1) ######################## sma26 = rpInd.EMAmvavgToArray(bs,26) sma12 = rpInd.EMAmvavgToArray(bs,12) diffs = rpInd.difftwoarrays(sma12,sma26) ## macd is the mvavg9 on this diff macdavg = rpInd.EMAmvavgToArray(diffs,9) macddiverg = rpInd.difftwoarrays(diffs,macdavg) datearray = rpInd.strip1string(lines,1) testlevel = float(10) RSIgain = rpInd.RSIGainLoss(bs,'gain') RSIloss = rpInd.RSIGainLoss(bs,'loss') rsiavggain = rpInd.RSImvavgToArray(RSIgain,14) rsiavgloss = rpInd.RSImvavgToArray(RSIloss,14) RS = rpInd.ratiotwoarrays(rsiavggain,rsiavgloss) ## rsi = 100 - ( 100 / (1 + RS)) rsiArray =[] for ratio in RS: rsi = min(100,(100 - ( 100 / (1 + ratio)))) rsiArray.append(rsi) #################
def process_ticks(lines,decimalboost,dur): ################ ##read variables from the control panel file cpfile = EXE + 'signalcreator.controlpanel.csv' paramlines = rpu_rp.CsvToLines(cpfile) varstrings = ['TimeLimitRecentSigs','SignalsToShow','DurationToShow'] var = {} for varstring in varstrings: for line in paramlines: if len(line) > 0: if line[0] == varstring: var[varstring] = line[1] bs = rpInd.strip1float(lines,5,decimalboost) ##raw close price bshighs = rpInd.strip1float(lines,3,decimalboost) bslows = rpInd.strip1float(lines,4,decimalboost) timestamparray = rpInd.strip1string(lines,1) symarray = rpInd.strip1string(lines,0) sym = symarray[1] durarray = [] for b in symarray: durarray.append(dur) ### create pivots rs and ss ### piv = rpInd.pivotpoint(bs,bshighs,bslows) R1 = rpInd.R1(piv,bshighs) ######################################## signbs = rpInd.show_sign(bs,'price') slopebs = rpInd.show_slope(bs,'price') ##### MA Cross ## macrossval = rpInd.difftwoarrays(rpInd.EMAmvavgToArray(bs,9),rpInd.EMAmvavgToArray(bs,21)) signmcd = rpInd.show_sign(macrossval,'mcd') crossesmcd = rpInd.show_crossover(signmcd,'mcd') slopemcd = rpInd.show_slope(macrossval,'mcd') MDarray = rpInd.makearrayJust2(timestamparray,symarray,durarray,bs,macrossval,crossesmcd,signmcd) ma = rpu_rp.grep_array_to_array(MDarray,'cross') rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', ma) ############################## from datetime import datetime prevt = 0 numsigs = len(ma) signum =0 import datetime as dt now = datetime.strftime(datetime.now(),time_format) now_dt = dt.datetime.strptime(now, time_format) prevbart_dt = now_dt for l in ma: sym = l[1] #.split()[0]) sigprice = float(l[3]) #.split()[0]) ## print l signum +=1 if len(l[0].split()) == 2: currentbar = l[0].split()[1] else: currentbar = (l[0].split()[0]) currentbar_dt = dt.datetime.strptime(currentbar, time_format) now_dt = dt.datetime.strptime(now, time_format) barToNow = (now_dt - currentbar_dt).seconds barToPrev = (currentbar_dt - prevbart_dt).seconds alerttxt = l[1] + '|' + str(barToNow) + '|' + str(barToPrev)+ '|' +str(l) prevbart_dt = currentbar_dt recentlimit = int(var['TimeLimitRecentSigs']) if barToNow < recentlimit and signum == numsigs: rpu_rp.WriteArrayToCsvfile(sigarea +'sigs.csv',ma) onesig = ma[len(ma)-1] Snaptickfile = DataDown + today + '.' + sym + '.ticksnaps.csv' rpu_rp.tail_to_txtfile(Snaptickfile,2,'lasttick') a5 = rpu_rp.CsvToLines('lasttick') a6= a5[0] bid = a6[1] ask = a6[3] bsize = a6[2] asize = a6[4] side =onesig[5] rside = 'BUY' if side == 'negcrossmcd': rside = 'SELL' sym =onesig[1] sigdur =onesig[2] pricedrift = round((sigprice / float(decimalboost)) - float(ask),4) timedrift = barToNow ## print barToPrev,'second lastsig..bid/ask',bid, ask,a6[2],'X',a6[4], print timedrift, pricedrift, sym, rside,sigdur, sigprice,bid,ask,bsize,asize,barToPrev print '=========='