3.15K 浏览
0

from tqsdk import TqApi, TargetPosTask

SYMBOL = “DCE.jd2005” # 合约代码
NDAY = 5 # 天数
K1 = 0.2 # 上轨K值
K2 = 0.2 # 下轨K值

api = TqApi()
print(“策略开始运行”)

quote = api.get_quote(SYMBOL)
klines = api.get_kline_serial(SYMBOL, 24 * 60 * 60) # 86400使用日线
target_pos = TargetPosTask(api, SYMBOL)

def dual_thrust(quote, klines):
current_open = klines.iloc[-1][“open”]
HH = max(klines.high.iloc[-NDAY – 1:-1]) # N日最高价的最高价
HC = max(klines.close.iloc[-NDAY – 1:-1]) # N日收盘价的最高价
LC = min(klines.close.iloc[-NDAY – 1:-1]) # N日收盘价的最低价
LL = min(klines.low.iloc[-NDAY – 1:-1]) # N日最低价的最低价
range = max(HH – LC, HC – LL)
buy_line = current_open + range * K1 # 上轨
sell_line = current_open – range * K2 # 下轨
print(“当前开盘价: %f, 上轨: %f, 下轨: %f” % (current_open, buy_line, sell_line))
return buy_line, sell_line

buy_line, sell_line = dual_thrust(quote, klines) # 获取上下轨

#取得昨天的上下轨
buy_line_2=buy_line.iloc[-2]
sell_line_2=sell_line.iloc[-2]

运行时出现错误提示: AttributeError: ‘numpy.float64’ object has no attribute ‘iloc’
Task was destroyed but it is pending!

应如何解决?

chengxiaohui321 已回答的问题 2020年7月11日