VeighNa量化社区
你的开源社区量化交易平台
LLM学员
avatar
加入于:
帖子: 20
声望: 1

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])
Administrator
avatar
加入于:
帖子: 4550
声望: 325

请打印下self.Atr_Stop和self.nloss_atr这两个变量是否为数组,报错显示是有数据变量是浮点数

LLM学员
avatar
加入于:
帖子: 20
声望: 1

谢谢 老师!

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】