我在比較兩個列表以生成買/賣信號。第一份清單是價格清單,第二份清單是這些價格的簡單移動平均數。比較兩個列表時輸出錯誤
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 = ''
for prices in range(len(result)):
for averages in range(len(avrg)):
if result[prices] > avrg[averages]:
signal = 'BUY'
elif result[prices] < avrg[averages]:
signal = 'SELL'
lst.append(signal)
輸出是
['BUY', 'BUY', 'BUY', 'BUY', 'BUY', 'SELL', 'BUY']
輸出應該
['BUY', 'BUY', 'SELL', 'SELL', 'SELL', 'SELL', 'BUY']