def checkForRise(ohlcvRows): module = "checkForRise" counter = 0 streak = 0 #print "Len of ohlcvRows is " + str(len(ohlcvRows)) #print ohlcvRows if len(ohlcvRows) >= 3: lowPeriodClosePrice = ohlcvRows[0][5] #print ohlcvRows[0][0] + " lowPeridClosePeriod initial value: " + str(lowPeriodClosePrice) numberOfPeriods = len(ohlcvRows) #print "numberOfPeriods = " + str(numberOfPeriods) #currentLow = ohlcvRows[0][5] currentHigh = 0 #print "currentHigh = " + str(currentHigh) for row in ohlcvRows: pairName = row[0] if counter < numberOfPeriods - 1: periodClose = ohlcvRows[counter][5] followingPeriod = ohlcvRows[counter + 1][5] periodTimestamp = ohlcvRows[counter + 1][1] #print "Close: " + str(periodClose) #print "Next Close: " + str(followingPeriod) #if followingPeriod < highPeriodClosePrice: if followingPeriod < periodClose and followingPeriod < lowPeriodClosePrice: lowPeriodClosePrice = followingPeriod #print "Setting new lowPeriodClosePeriod: " + str(lowPeriodClosePrice) if currentHigh == 0: currentHigh = lowPeriodClosePrice if followingPeriod > currentHigh: currentHigh = followingPeriod streak += 1 #print "Rise! " + str(streak) + " at followingPeriod price " + str(followingPeriod) #print #dips.append(followingPeriod) if streak == 3: print module + ": We've 3 in a rise for " + pairName riseStartTime = ohlcvRows[0][1] #highPeriodClosePrice = ohlcvRows[0][5] #lowPeriodClosePrice = ohlcvRows[counter+1][5] highPeriodClosePrice = ohlcvRows[counter + 1][5] print module + ": Rise Start Time: " + str( riseStartTime) print module + ": Low price: " + str( lowPeriodClosePrice) print module + ": High price:" + str( highPeriodClosePrice) trigger = highPeriodClosePrice - ( highPeriodClosePrice - lowPeriodClosePrice) / 2 #print "Trigger: " + str(trigger) hot = True dbMod.setHotsetTrigger(pairName, hot, trigger, lowPeriodClosePrice, highPeriodClosePrice) #print print module + "Set trigger for " + pairName + " at value " + str( trigger) + " at time " + str(periodTimestamp) counter += 1
def checkForDip(ohlcvRows): logTime = datetime.datetime.now() print "DEF: CheckForDip: " + str(logTime) print counter = 0 streak = 0 #print "Len of ohlcvRows is " + str(len(ohlcvRows)) #print ohlcvRows if len(ohlcvRows) >= 3: highPeriodClosePrice = ohlcvRows[0][5] numberOfPeriods = len(ohlcvRows) #print "numberOfPeriods = " + str(numberOfPeriods) #currentLow = ohlcvRows[0][5] currentLow = 99999 #print "currentLow = " + str(currentLow) dips = [] for row in ohlcvRows: pairName = row[0] if counter < numberOfPeriods - 1: periodClose = ohlcvRows[counter][5] followingPeriod = ohlcvRows[counter + 1][5] periodTimestamp = ohlcvRows[counter + 1][1] #print "Close: " + str(periodClose) #print "Next Close: " + str(followingPeriod) # Adding check for new highs before a dip if followingPeriod > highPeriodClosePrice and followingPeriod > highPeriodClosePrice: highPeriodClosePrice = followingPeriod if currentLow == 99999: currentLow = highPeriodClosePrice #print "Readjusting currentLow: " + str(currentLow) + " for " + pairName if followingPeriod < currentLow: currentLow = followingPeriod streak += 1 #print "Dip! + " + str(streak) + " at followingPeriod price " + str(followingPeriod) #print dips.append(followingPeriod) if streak == 3: #print "We've 3 in a dip" dipStartTime = ohlcvRows[0][1] #print dips #print #highPeriodClosePrice = ohlcvRows[0][5] #lowPeriodClosePrice = ohlcvRows[counter+1][5] lowPeriodClosePrice = ohlcvRows[counter + 1][5] #print "Dip Start Time: " + str(dipStartTime) #print "High price: " + str(highPeriodClosePrice) #print "Low price:" + str(lowPeriodClosePrice) trigger = lowPeriodClosePrice + ( highPeriodClosePrice - lowPeriodClosePrice) / 2 #print "Trigger: " + str(trigger) hot = True dbMod.setHotsetTrigger(pairName, hot, trigger, lowPeriodClosePrice, highPeriodClosePrice) #print #print "Set trigger for " + pairName + " at value " + str(trigger) + " at time " + str(periodTimestamp) counter += 1
def checkForDip(ohlcvRows): logTime = datetime.datetime.now() print "DEF: CheckForDip: " + str(logTime) print counter = 0 counter1 = 0 streak = 0 #print "Len of ohlcvRows is " + str(len(ohlcvRows)) #print ohlcvRows newStartTime = 0 reset = False highPeriodClosePrice = ohlcvRows[0][5] startingPrice = highPeriodClosePrice numberOfPeriods = len(ohlcvRows) for row in ohlcvRows: pairName = row[0] if counter1 < numberOfPeriods-1: followingPeriod = ohlcvRows[counter1+1][5] periodTimeStamp = ohlcvRows[counter1+1][1] if followingPeriod > highPeriodClosePrice: highPeriodClosePrice = followingPeriod newStartTime = periodTimeStamp counter1 += 1 if highPeriodClosePrice > startingPrice: #RESET newStartPrice = highPeriodClosePrice dbMod.resetPotential(pairName, newStartPrice, newStartTime) print "RESET potential " + pairName + ", new startPrice = " + str(newStartPrice) reset = True if len(ohlcvRows) >= 3 and reset == False: #print "numberOfPeriods = " + str(numberOfPeriods) #currentLow = ohlcvRows[0][5] currentLow = 99999 #print "currentLow = " + str(currentLow) dips = [] for row in ohlcvRows: pairName = row[0] if counter < numberOfPeriods-1: periodClose = ohlcvRows[counter][5] followingPeriod = ohlcvRows[counter+1][5] periodTimestamp = ohlcvRows[counter+1][1] #print "Close: " + str(periodClose) #print "Next Close: " + str(followingPeriod) if followingPeriod < currentLow: print "Dip! + " + str(streak) + " at followingPeriod price " + str(followingPeriod) + " for " + pairName + " at time " + str(periodTimestamp) + " currentLow: " + str(currentLow) currentLow = followingPeriod streak += 1 print dips.append(followingPeriod) if streak == 3: #print "We've 3 in a dip" dipStartTime = ohlcvRows[0][1] #print dips #print #highPeriodClosePrice = ohlcvRows[0][5] #lowPeriodClosePrice = ohlcvRows[counter+1][5] lowPeriodClosePrice = ohlcvRows[counter+1][5] #print "Dip Start Time: " + str(dipStartTime) #print "High price: " + str(highPeriodClosePrice) #print "Low price:" + str(lowPeriodClosePrice) trigger = lowPeriodClosePrice + (highPeriodClosePrice - lowPeriodClosePrice)/2 #print "Trigger: " + str(trigger) hot = True dbMod.setHotsetTrigger(pairName, hot, trigger, lowPeriodClosePrice, highPeriodClosePrice) #print #print "Set trigger for " + pairName + " at value " + str(trigger) + " at time " + str(periodTimestamp) counter += 1