3.97K 浏览
0

from tqsdk import TqApi, TqSim, tafunc

api = TqApi(TqSim())
klines = api.get_kline_serial(“SHFE.rb2005”, 24 * 60 * 60)
crossup = tafunc.crossup(klines.close.iloc[-1], tafunc.ma(klines.close, 10))
print(list(crossup))

执行结果

>>> from tqsdk import TqApi, TqSim, tafunc
>>>
>>> api = TqApi(TqSim())
2019-12-27 12:47:20,549 – INFO – 通知: 与 wss://openmd.shinnytech.com/t/md/front/mobile 的网络连接已建立
>>> klines = api.get_kline_serial(“SHFE.rb2005”, 24 * 60 * 60)
>>> crossup = tafunc.crossup(klines.close.iloc[-1], tafunc.ma(klines.close, 10))
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “C:\Users\pzq\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\tafunc.py”, line 221, in crossup
crossup_data = pd.Series(np.where((a > b) & (a.shift(1) <= b.shift(1)), 1, 0))
AttributeError: ‘numpy.float64’ object has no attribute ‘shift’
>>> print(list(crossup))
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
>>>

Jesse Livermore 已回答的问题 2019年12月27日
0

1.引号错了
2.crossup参数类型错了

from tqsdk import TqApi, TqSim, tafunc

api = TqApi(TqSim())
klines = api.get_kline_serial(“SHFE.rb2005”, 24 * 60 * 60)
crossup = tafunc.crossup(klines.close, tafunc.ma(klines.close, 10))
print(list(crossup))

Jesse Livermore 已回答的问题 2019年12月27日