QuantConnect / QuantConnect/Lean

Market On Open isn't accurate

Open
#9,503 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
21.7k
Forks
5.3k
Avg merge
2d 22h
Merged PRs (30d)
34

Description

Expected Behavior

Market on open should mimic the official open price for the day when subscribing to regular data feed (such as minute) as outlined here
https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/market-on-open-orders

Actual Behavior

this backtest isnt actually producing any results as described in the article.
as well i have noticed on other backtests that when subscribing to minute data the qc takes the 2nd bar after the open (the bar of 09:32 and not and not 09:31 as outlined in your article... )

Potential Solution

might be related to this:

For MOO, official opening price is only used in the Tick branch: EquityFillModel.cs (line 458) looks for OfficialOpen | OpeningPrints.
But our algo subscribes to minute TradeBars, so LEAN uses this branch instead: EquityFillModel.cs (line 503). That branch literally does:

_var tradeBar = asset.Cache.GetData<TradeBar>();
fill.FillPrice = tradeBar.Open;_

at line 505 (line 505) and line 518 (line 518).
So yes: with minute bars, QC MOO can fill from the cached minute bar Open, not the official daily open. If the cached bar is the 09:31-09:32 bar, the report shows 09:32 and price matches 09:31 open.

Reproducing the Problem

create a backtest with subscribing to minute data and do some MOO, see that trade prices are not the daily open prices.

System Information

QC CLoud

Checklist
  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with EquityFillModel.cs, especially the Tick and TradeBar branches cited in the report, and reproduce the behavior with a minute-data backtest containing market-on-open orders. Check how the cached TradeBar and official opening price are selected, then add or update focused tests so the fill uses the expected daily open and the reported timing is corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.