Found a bug that was confirmed by QC support, but wanted to make it known to the community as well.
I submitted a short limit order on 10/03 at 9:15am EST (15 min before the market open) at a price of 10.58 (5% above the closing price the day before). On 10/03, the price opened at 13.89, hit a low of 11.35, and closed at 11.51. The short limit order should have filled at the open at 13.89, but instead filled at the low of 11.35. You can run the code below and I've printed out some Debug statements as proof.
Date: 2022-10-03 09:15:00; Submitted Sell Limit at 10.58
Date: 2022-10-04 00:00:00; FillPrice: 11.35
Date: 2022-10-04 00:00:00; Open: 13.89; High: 15.51; Low:11.35; Close:11.51
# region imports
from AlgorithmImports import *
# endregion
class BackTestBug(QCAlgorithm):
def Initialize(self):
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.SplitAdjusted
self.SetStartDate(2022, 10, 1) # Set Start Date
self.SetEndDate(2022, 10, 3)
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("ATXI", Resolution.Daily)
self.AddEquity("SPY", Resolution.Daily)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", -15), self.FillOpenPositions)
def FillOpenPositions(self):
symbol = self.Symbol("ATXI")
history = self.History(symbol, 1, Resolution.Daily)
symbolHistory = history.loc[symbol]
for bar in symbolHistory.itertuples():
close = bar.close
limitPrice = round(close * 1.05, 2)
orderProperties = OrderProperties()
orderProperties.TimeInForce = TimeInForce.GoodTilDate(self.Time + timedelta(hours=20))
self.LimitOrder(symbol, -10, limitPrice, orderProperties=orderProperties)
self.Debug("Date: {0}; Submitted Sell Limit at {1}".format(self.Time, limitPrice))
def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
symbol = order.Symbol
if order.Status == OrderStatus.Filled:
fillPrice = orderEvent.FillPrice
self.Debug("Date: {0}; FillPrice: {1}".format(self.Time, fillPrice))
history = self.History(symbol, 1, Resolution.Daily).loc[symbol]
for bar in history.itertuples():
o = bar.open
h = bar.high
l = bar.low
c = bar.close
self.Debug("Date: {0}; Open: {1}; High: {2}; Low:{3}; Close:{4}".format(self.Time, o, h, l, c))
LoganW
Thanks for sharing. Does this only occur when orders are place outside of RTH and/or only daily resolution?
Chetan Prabhu
What is RTH? I've only tested on daily resolution, so may or may not not be an issue in other timeframes.
LoganW
Sorry, “Regular Trading Hours”
Chetan Prabhu
Ah, yes, it could be limited to trades that are placed outside of RTH as well
Chetan Prabhu
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!