from tqsdk import TqApi, TqSim, tafunc
from tqsdk.ta import MACD
api = TqApi(TqSim())
klines = api.get_kline_serial(“DCE.i2009”, 24 * 60 * 60)
macd=MACD(klines,12,26,9)
mbar=macd[“bar”]
mbar_crossup_0 = tafunc.crossup(mbar,0)
api.close()
运行时总是出现错误提示:
crossdown_data = pd.Series(np.where((a < b) & (a.shift(1) >= b.shift(1)), 1, 0))
AttributeError: ‘int’ object has no attribute ‘shift’
Task was destroyed but it is pending!
应如何解决?
west 已回答的问题 2020年6月15日
换成diff金叉dea,还是会出错:
from datetime import date, datetime
from tqsdk import TqApi, TqSim, TargetPosTask, TqAccount, tafunc, TqBacktest, TqReplay
from tqsdk.ta import MACD
api = TqApi(TqSim(),backtest=TqBacktest(start_dt=date(2020,5,1), end_dt=date(2020,6,12)),web_gui=”:1234″)
SYMBOL=”DCE.i2009″
klines = api.get_kline_serial(SYMBOL, 24 * 60 * 60)
quote = api.get_quote(SYMBOL)
macd=MACD(klines,12,26,9)
while True:
api.wait_update()
if api.is_changing(klines.iloc[-1], [“datetime”, “open”]):
macd=MACD(klines,12,26,9)
if api.is_changing(quote, “last_price”):
mdif=macd[“diff”]
mdea=macd[“dea”]
if tafunc.crossup(mdif,mdea) :
target_pos.set_target_volume(1)
api.close()
运行后出现错误提示。