QMT中passorder函数的使用疑问

在QMT量化交易系统中,passorder 是用于下单的核心函数之一,支持股票、期货、期权等多种交易类型。由于其具备快速交易功能,有时会出现当日买入后立即发出卖出请求的情况,这可能会影响策略的执行效果。

如何避免这种情况?

  1. 通过持仓状态控制交易在每次交易前检查当前是否已持有目标股票,避免重复买卖。例如:def handlebar(ContextInfo): positions = get_trade_detail_data(accountid, 'stock', 'position') current_hold = False for pos in positions: if pos.m_strInstrumentID == '000001.SZ': current_hold = True break if not current_hold and 买入条件: passorder(...) elif current_hold and 卖出条件: passorder(...)
  2. 使用交易标志控制设置一个标志位记录当日是否已进行过交易,防止同一日内多次操作:def init(ContextInfo): ContextInfo.traded_today = False def handlebar(ContextInfo): if not ContextInfo.traded_today and 买入条件: passorder(...) ContextInfo.traded_today = True
  3. 结合时间限制进行交易限定交易时间范围,避免在非交易时段频繁操作:def handlebar(ContextInfo): current_time = ContextInfo.get_bar_timetag(ContextInfo.barpos) hour_min = timetag_to_datetime(current_time, "%H%M") if '0930' <= hour_min <= '1100' and 买入条件: passorder(...)

注意事项:

  • passorder 是异步调用,不会等待委托结果;
  • 在非 handlebar 函数中下单建议设置 quickTrade=2
  • 实盘策略需设计委托状态保存机制,防止超单。

综合使用以上方法,可以有效避免因 passorder 引起的重复或无效交易问题。

如需进一步了解QMT的使用、策略编写或自动化交易配置,欢迎私信咨询,我们将为你提供详细指导!



温馨提示:投资有风险,选择需谨慎。

相关文章