用画线工具怎么在五分钟图里画前一日结算价线.
问题已经解决 # 引入TqSdk模块 from datetime import date from tqsdk import TqApi, TargetPosTask,TqBacktest # 创建api实例,设置web_gui=True生成图形化界面 api = TqApi(backtest=TqBacktest(start_dt=date(2019, 12, 1), end_dt=date(2020, 1, 30)),web_gui=True) # 订阅 cu2002 合约的10秒线 klines = api.get_kline_serial(“CZCE.MA005”, 60*5) klines1 = api.get_kline_serial(“CZCE.MA005”, 60*60*24) quote = api.get_quote(“CZCE.MA005”) # 创建 m1909 的目标持仓 task,该 task 负责调整 m1909 的仓位到指定的目标仓位 target_pos = TargetPosTask(api, “CZCE.MA005”) while True: api.wait_update() if api.is_changing(klines):
high = klines1.high.iloc[-2] # 前一日的最高价 low = klines1.low.iloc[-2] # 前一日的最低价 pivot=(high+low)/2
#print(“当前时间”,quote.datetime,”当前价位” ,quote.last_price,”前一中间价”,pivot) print(“当前时间”,quote.datetime,”前结”,pivot,”up1″,up2,”down1″,down2) klines[“ma_MAIN”] = pivot #api.draw_line(klines, -1,pivot, -1, pivot, line_type=”RAY”, color=0xFFFF9900, width=3)
你这中间价和结算不是一回事吧
我要求的确实是中间价,结算价还没有写出来。
问题已经解决
# 引入TqSdk模块
from datetime import date
from tqsdk import TqApi, TargetPosTask,TqBacktest
# 创建api实例,设置web_gui=True生成图形化界面
api = TqApi(backtest=TqBacktest(start_dt=date(2019, 12, 1), end_dt=date(2020, 1, 30)),web_gui=True)
# 订阅 cu2002 合约的10秒线
klines = api.get_kline_serial(“CZCE.MA005”, 60*5)
klines1 = api.get_kline_serial(“CZCE.MA005”, 60*60*24)
quote = api.get_quote(“CZCE.MA005”)
# 创建 m1909 的目标持仓 task,该 task 负责调整 m1909 的仓位到指定的目标仓位
target_pos = TargetPosTask(api, “CZCE.MA005”)
while True:
api.wait_update()
if api.is_changing(klines):
high = klines1.high.iloc[-2] # 前一日的最高价
low = klines1.low.iloc[-2] # 前一日的最低价
pivot=(high+low)/2
#print(“当前时间”,quote.datetime,”当前价位” ,quote.last_price,”前一中间价”,pivot)
print(“当前时间”,quote.datetime,”前结”,pivot,”up1″,up2,”down1″,down2)
klines[“ma_MAIN”] = pivot
#api.draw_line(klines, -1,pivot, -1, pivot, line_type=”RAY”, color=0xFFFF9900, width=3)