File "D:\vnstudio\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "D:\vnstudio\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "D:\yxl _vny\vnpy\app\cta_backtester\engine.py", line 172, in run_backtesting
engine.run_backtesting()
File "D:\yxl _vny\vnpy\app\cta_strategy\backtesting.py", line 293, in run_backtesting
func(data)
File "D:\yxl _vny\vnpy\app\cta_strategy\backtesting.py", line 722, in new_bar
self.strategy.on_bar(bar)
File "D:\yxl _vny\strategies\cuatro.py", line 99, in on_bar
self.bg.update_bar(bar)
File "D:\yxl _vny\vnpy\trader\utility.py", line 282, in update_bar
self.on_window_bar(self.window_bar)
File "D:\yxl _vny\strategies\cuatro.py", line 122, in on_min_bar
self.Atr_Stop[x] = self.Atr_Stop[x-1] if self.Atr_Stop[x-1] > (self.close_now - self.nloss_atr[x]) else (self.close_now - self.nloss_atr[x])
TypeError: 'float' object is not subscriptable
代码如下:
《 self.Atr_Stop = np.zeros(100-self.art_window)》
for x in range(self.art_window + 1,len(self.am.close)):
self.close_now =am.close[x-1]
self.close_front=am.close[x-2]
if (self.close_now > self.Atr_Stop[x-1]) and (self.close_front > self.Atr_Stop[x-2]):
self.Atr_Stop[x] = self.Atr_Stop[x-1] if self.Atr_Stop[x-1] > (self.close_now - self.nloss_atr[x]) else (self.close_now - self.nloss_atr[x])
elif self.close_now < self.Atr_Stop[x-1] and self.close_front < self.Atr_Stop[x-2]:
self.Atr_Stop[x] = self.Atr_Stop[x-1] if self.Atr_Stop[x-1] < (self.close_now + self.nloss_atr[x]) else (self.close_now + self.nloss_atr[x])