错误类型列表索引超出范围

时间:2017-12-12 15:03:46

标签: python

close =[29.87,30.24,30.10,28.90,28.92,28.48,28.56,27.56,28.47,28.28,27.49,27.23,26.35,26.33,27.03,26.22,26.01,25.46,27.03,27.45,28.36,28.43,27.95,29.01,29.38,29.36,28.91,30.61,30.05,30.19,31.12,30.54,29.78,30.04]
low =[29.41,29.32,29.96,28.74,28.56,28.41,28.08,27.43,27.66,27.83,27.40,27.09,26.18,26.13,26.63,26.13,25.43,25.35,25.88,26.96,27.14,28.01,27.88,27.99,28.76,29.14,28.71,28.93,30.03,29.39,30.14,30.43,29.35,29.99]
high=[30.20,30.28,30.45,29.35,29.35,29.29,28.83,28.73,28.67,28.85,28.64,27.68,27.21,26.87,27.41,26.94,26.52,26.52,27.09,27.69,28.45,28.53,28.67,29.01,29.87,29.80,29.75,30.65,30.60,30.76,31.17,30.89,30.04,30.66]
maxvalue_bar=[]
TR1_bar=[]
TR4_bar=[]
TRwindow=[]
TRwindow_bar=[]

##Step-1== Calculate TR..Here TR is maxvalue

for i in range(1,len(high)):
    maxvalue=max((high[i]-low[i]),abs(high[i]-close[i-1]),abs(low[i]-close[i-1]))
    maxvalue_bar.append(maxvalue)
#print(maxvalue_bar)
###Calculate TR4......4Days TR value (maxvalue_bar)
window=14
TRwindow_bar=sum(maxvalue_bar[0:window])
print(TRwindow_bar)

for i in range(1,len(maxvalue_bar)-window+1):
    TRwindow = maxvalue_bar[window+i]+ TRwindow[window+i-1]- (TRwindow[window+i-1]/window)
    TRwindow_bar.append(TRwindow)
print(TRwindow_bar) 

这显示列表中的一些错误,例如列表索引超出范围.Errow是最后几行......

我的目标与以下相同

A=[]
B=[]
B14=sum(A1:A14)
B15=A15+B14-(B14/14)
B16=A16+B15-(B15/14)

这必须继续.....这里

1 个答案:

答案 0 :(得分:0)

你在第7行初始化TRwindow作为空列表[],然后在第22行尝试访问它:TRwindow[window+i-1]这是无效的,因为TRwindow仍然没有任何内容,它是' s len(TRwindow)为0,因此您无法访问不存在的内容,因此您收到索引超出范围错误。