逐tick回测,原本开平仓只有六次,加入收盘平仓后,疯狂开平仓,请教如何解决?
if api.is_changing(quote, "datetime") and position.pos_short + position.pos_long >= 1: now = datetime.strptime(quote.datetime, "%Y-%m-%d %H:%M:%S.%f") print(now) if now.hour == CLOSE_HOUR and now.minute >= CLOSE_MINUTE: # 到达平仓时间: 平仓 print("临近本交易日收盘: 平仓") #全平# #平空 if position.pos_short_his >= 1:#平昨空 api.insert_order(symbol=SYMBOL, direction="BUY", offset="CLOSE", volume=position.pos_short_his)# if position.pos_short_today >= 1:#平今空 if SYMBOL[:4]=="SHFE": api.insert_order(symbol=SYMBOL, direction="BUY", offset="CLOSETODAY", volume=position.pos_short_today) else: api.insert_order(symbol=SYMBOL, direction="BUY", offset="CLOSE", volume=position.pos_short_today)# #平多 if position.pos_long_his >= 1:#平昨多 api.insert_order(symbol=SYMBOL, direction="SELL", offset="CLOSE", volume=position.pos_long_his) if position.pos_long_today >= 1:#平今多# if SYMBOL[:4]=="SHFE": api.insert_order(symbol=SYMBOL, direction="SELL", offset="CLOSETODAY", volume=position.pos_long_today)# else: api.insert_order(symbol=SYMBOL, direction="SELL", offset="CLOSE", volume=position.pos_long_today)#
经大神指点,原来收盘平仓时间段内应该禁止开仓