VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 85
声望: 3

策略源代码贴在这里 http://paste.debian.net/1225023/
就是当1小时MACD金叉或死叉时,根据5分钟MACD状态进行买卖。逻辑很简单,但死活运行不了。麻烦大佬们帮忙看看,on_1hour_bar函数是不是有错?我的数据库里有1小时数据的。加载策略文件提示如下错误:
17:38:31 初始化CTA回测引擎
17:38:31 策略文件strategies.multi_timeframe_macd加载失败,触发异常:
Traceback (most recent call last):
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/site-packages/vnpy_ctabacktester/engine.py", line 109, in load_strategy_class_from_module
module = importlib.import_module(module_name)
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/yinxiuqu/strategies/multi_timeframe_macd.py", line 88
if self.dif5m > self.long_line and self.dea5m > self.long_line and self.dif5m > self.dea5m and self.macd_trend = 1:
^
SyntaxError: invalid syntax

17:38:31 策略文件加载完成
17:38:31 数据服务初始化成功

Member
avatar
加入于:
帖子: 387
声望: 20

从报错看是语法错误,源于最后这个比较:

self.macd_trend = 1

应该是==符号

Member
avatar
加入于:
帖子: 85
声望: 3

MTF wrote:

从报错看是语法错误,源于最后这个比较:

self.macd_trend = 1

应该是==符号

谢谢搞定了,在回测过程又有错误:
10:02:03 触发异常,回测终止
10:02:03 Traceback (most recent call last):
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/site-packages/vnpy_ctastrategy/backtesting.py", line 228, in run_backtesting
self.callback(data)
File "/home/yinxiuqu/strategies/multi_timeframe_macd.py", line 71, in on_bar
self.bg1h.update_bar(bar)
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/site-packages/vnpy/trader/utility.py", line 268, in update_bar
self.update_bar_hour_window(bar)
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/site-packages/vnpy/trader/utility.py", line 383, in update_bar_hour_window
self.on_hour_bar(finished_bar)
File "/home/yinxiuqu/anaconda3/envs/vnpy2.8/lib/python3.7/site-packages/vnpy/trader/utility.py", line 388, in on_hour_bar
self.on_window_bar(bar)
File "/home/yinxiuqu/strategies/multi_timeframe_macd.py", line 111, in on_1hour_bar
self.dif1h, self.dea1h, self.hist1h = self.am1h.macd(self.close, self.fast_period, self.slow_period, self.signal_period)
AttributeError: 'MultiTimeframeMacd' object has no attribute 'close'

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

沪公网安备 31011502017034号

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