python - Incorrect Output While Comparing Two Lists -


i'm trying compare 2 lists generate buy/sell signals. first list list of prices, while second list simple moving average prices.

result = [590.0, 600.0, 590.0, 580.0, 570.0, 560.0, 570.0] avrg = [580.0, 590.0, 593.33, 590.0, 580.0, 570.0, 566.67] signal = ''  prices in range(len(result)):     averages in range(len(avrg)):         if result[prices] > avrg[averages]:             signal = 'buy'         elif result[prices] < avrg[averages]:             signal = 'sell'     lst.append(signal) 

output is

['buy', 'buy', 'buy', 'buy', 'buy', 'sell', 'buy'] 

the output should be

['buy', 'buy', 'sell', 'sell', 'sell', 'sell', 'buy'] 

result = [590.0, 600.0, 590.0, 580.0, 570.0, 560.0, 570.0] avrg = [580.0, 590.0, 593.33, 590.0, 580.0, 570.0, 566.67] signal = [] in range(len(result)):   if (result[i] > avrg[i]):     signal.append('buy')   else:     signal.append('sell') 

gives

>>> signal ['buy', 'buy', 'sell', 'sell', 'sell', 'sell', 'buy'] 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -