Dec-13-2018, 07:56 PM
x = 50 list_of_gains = [] while x < len(stock['Returns']) - 4: if stock['Returns'][x] > 0 and stock['Returns'][x + 1] > 0 and \ stock['Returns'][x + 2] > 0 and stock['Returns'][x + 3] > 0: if stock['Volume'][x] > stock['Avg'][x] and stock['Volume'][x + 1] > stock['Avg'][x + 1] and \ stock['Volume'][x + 2] > stock['Avg'][x + 2] and stock['Volume'][x + 3] > stock['Avg'][x + 3]: # stock['Signals'][x + 4] = 1 list_of_gains.append(stock['Returns'][x + 4]) else: pass x += 1 return list_of_gainsIm trying to work with pandas and tried to write a way that would find if a stock was increasing 4 days in a row and has above average volume. I have the minus four in the while loop condition to keep it in range. x starts at 50 because the stock['Avg'] is a 50 day moving average of volume. I tried finding ways to write this better for a while but nothing seemed to work.