Пример #1
0
def make_dur_state(sym, dur, threshold, indlist):
    ##    print sym,dur
    rpInd.create_states_filesWboost(sym, dur, today, threshold, indlist)
    for ind in indlist:
        mode = 'boost'
        state = rpInd.ShowRecentState(sym, dur, ind, mode)
        stateAge = rpInd.ShowRecentAge(sym, dur, ind, mode)
        val = rpInd.ShowRecentStateValue(sym, dur, ind, mode)
        crxtime = rpInd.ShowRecentCRXTime(sym, dur, ind, mode)
        price = rpInd.ShowRecentClPrice(sym, dur, ind, mode)

        print state, stateAge, val, ind, crxtime, price, sym, dur, threshold
Пример #2
0
def snapshot_sym(sym, today, durslist):
    ##    print 'got her'
    text = []
    barlist = ['1min', '3mins', '5mins', '15mins', '1hour']
    basisfile = DataDown + today + '.' + sym + '.' + '5secs' + '.both.csv'
    TicksUtile.assemble_dur_bars(today, sym, '1hour', 'initial', basisfile)
    posstate = rpInd.ShowRecentPositionState(sym)
    text.append(posstate + sym)
    threshold = 0.0
    indlist = ['mcross', 'kupper']
    ##    print posstate,sym,'recentstate age val | lastcrosstime| name USING THRESH ', threshold
    textline = 'recentstate age val name USING THRESH ' + str(threshold)
    text.append(textline)
    for dur in barlist:
        ##        print dur
        threshold = 0.0
        if dur == '1min':
            threshold = 0.1
##        print sym,dur
##        make_dur_state(sym,dur,threshold,indlist)
        basisdur = '5secs'
        startmode = 'initialize'
        basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv'
        TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile)
        ### this relys on the sig creator to assemble each time
        rpInd.create_states_files(sym, dur, today, threshold, indlist)
        indlist = ['mcross']
        for ind in indlist:
            mode = 'noboost'
            state = rpInd.ShowRecentState(sym, dur, ind, mode)
            stateAge = rpInd.ShowRecentAge(sym, dur, ind, mode)
            val = rpInd.ShowRecentStateValue(sym, dur, ind, mode)
            crxtime = rpInd.ShowRecentCRXTime(sym, dur, ind, mode)
            price = rpInd.ShowRecentClPrice(sym, dur, ind, mode)
            if ind == 'mcross':
                textline = []
                tlist = [
                    state, dur, stateAge, val, price, crxtime, threshold, sym,
                    ind
                ]
                for t in tlist:
                    textline.append(str(t))
                text.append(str(textline))

                print state, dur, stateAge, val, price, crxtime, threshold, sym, ind
##        Triggers = rpInd.Trigger_from_states(sym,dur,'kupper')
##        lasttwo = rpu_rp.tail_array_to_array(Triggers,2)
##        for l in lasttwo:
##            print l[0],l[1],l[7],l[5],l[8],l[11],'kupperflips'
    print recenttick(sym)
    print '======================='
    return text
def make_dur_state(sym, dur, threshold, indlist):
    ##    print sym,dur, crxcode
    rpInd.create_states_files(sym, dur, today, threshold, indlist)
    for ind in indlist:
        state = rpInd.ShowRecentState(sym, dur, ind)
        stateAge = rpInd.ShowRecentAge(sym, dur, ind)
        val = rpInd.ShowRecentStateValue(sym, dur, ind)
        crxtime = rpInd.ShowRecentCRXTime(sym, dur, ind)
        crxcode = rpInd.ShowRecentCRXCode(sym, dur, ind)
        price = rpInd.ShowRecentClPrice(sym, dur, ind)

        ##        print  state, stateAge,val,ind, crxtime,price , sym, dur, threshold, crxcode
        print crxcode, sym
Пример #4
0
    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:
        ##        print sym
        ##        rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) # flush the file to keep all sigs
        TicksUtile.prepare_tickfilesto5secBars(
            today, sym,
            startmode)  ## merge the 5secddload with 5sec recents > 5sec boths
        ####################################
        ##        rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', [])
        state15 = rpInd.ShowRecentState(sym, '15mins', 'mcross')
        stateAge15 = rpInd.ShowRecentAge(sym, '15mins', 'mcross')

        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 = [
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'
Пример #6
0
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