You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Strategy订单未按限价成交:ORB策略定时订单问题排查

问题分析与修正方案

核心错误1:限价单类型逻辑完全颠倒

你用limit限价单来执行ORB突破交易,这和突破策略的逻辑完全相反:

  • 做多时,strategy.long的限价单要求当前价格 ≤ 限价价格才会成交。你把限价设为ORB高点orbHighPrice,只有价格回落至该高点时才会成交,完全违背“突破高点做多”的ORB核心逻辑。正确做法是用止损单(stop),当价格向上突破orbHighPrice时自动成交做多单。
  • 做空时,strategy.short的限价单要求当前价格 ≥ 限价价格才会成交。你把限价设为ORB低点orbLowPrice,只有价格反弹至该低点时才会成交,不符合“突破低点做空”的逻辑,同样要改用止损单。

核心错误2:订单触发时机控制不精准

ordertime定义的是03:30-04:31的时间范围,该时间段内的每根K线都会触发订单条件。虽然TradedToday会阻止当天重复发单,但如果第一根K线发出的订单未成交,后续K线也不会重新尝试,可能错过成交窗口。建议限定只在时间窗口的第一根确认K线触发订单。

修正后的关键代码示例

基础修正:调整订单类型与触发时机

var bool TradedToday = false
if timeframe.change("D")
    TradedToday := false

// 仅在时间窗口的第一根已确认K线触发
bool inOrderTime = time(timeframe.period, "0330-0431:1234567") and barstate.isconfirmed

// 做多:突破ORB高点用止损单成交
if not TradedToday and inOrderTime and inTradeWindow
    strategy.entry("Enter Long", strategy.long, stop=orbHighPrice)
    TradedToday := true

// 做空:突破ORB低点用止损单成交
if not TradedToday and inOrderTime and inTradeWindow
    strategy.entry("Enter Short", strategy.short, stop=orbLowPrice)
    TradedToday := true

进阶优化:整合止损止盈设置

可以直接在strategy.entry中绑定止损止盈参数,替代单独的交叉判断逻辑,代码更简洁:

orbRange = orbHighPrice - orbLowPrice

// 做多同时设置止损止盈
if not TradedToday and inOrderTime and inTradeWindow
    strategy.entry("Enter Long", strategy.long, stop=orbHighPrice, 
                  stop_loss=orbHighPrice - orbRange*0.5, 
                  limit=orbHighPrice + orbRange*1.0)
    TradedToday := true

// 做空同时设置止损止盈
if not TradedToday and inOrderTime and inTradeWindow
    strategy.entry("Enter Short", strategy.short, stop=orbLowPrice, 
                  stop_loss=orbLowPrice + orbRange*0.5, 
                  limit=orbLowPrice - orbRange*1.0)
    TradedToday := true

额外注意事项

  • 确认inTradeWindow变量的逻辑无错误,避免额外限制订单触发。
  • 检查ORB高低价的更新逻辑,确保仅在指定的ORB时段(如早盘)更新,防止后续K线错误覆盖orbHighPrice和orbLowPrice。

内容的提问来源于stack exchange,提问作者Yoshidk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 17:35:24