I have continuously received the following error when attempting to backtest and do not know how to resolve it:
Error Message
[ERROR] FATAL UNHANDLED EXCEPTION:Engine.Run(): Error running algorithm System.ArgumentException: Unable to locate next market open within two weeks., at QuantConnect.Securities.SecurityExchangeHours.GetNextMarketOpen(DateTime localDateTime, Boolean extendedMarketHours) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Securities/SecurityExchangeHours.cs:line 320, at QuantConnect.Scheduling.TimeRules.<>c__DisplayClass14_0.b__1(DateTime date) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Scheduling/TimeRules.cs:line 172, at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext(), at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext(), at QuantConnect.Scheduling.ScheduledEvent.get_NextEventUtcTime() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Scheduling/ScheduledEvent.cs:line 80, at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.<>c.b__11_0(KeyValuePair`2 x) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 158, at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count), at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count), at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count), at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext(), at System.Linq.Enumerable.SelectIPartitionIterator`2.ToList(), at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source), at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.GetScheduledEventsSortedByTime() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 156, at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.Setup(IAlgorithm algorithm, AlgorithmNodePacket job, IResultHandler resultHandler, IApi api, IIsolatorLimitResultProvider isolatorLimitProvider) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 52, at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/Engine.cs:line 295
Mia Alissi
The error message you're seeing is related to the scheduling of events in your algorithm. It seems like your algorithm is trying to schedule an event for the next market open, but it's unable to find a market open time within the next two weeks.
This could be due to a few reasons:
The security you're trading might not be trading in the next two weeks. This could be the case if the security has been delisted, or if it's a future or option that has expired.
The exchange hours for the security might be incorrectly set. This could happen if there's an issue with the data for the security.
There might be an issue with the way you're scheduling the event in your algorithm.
Without seeing your code, it's hard to say exactly what the issue is. However, you might want to check the securities you're trading and how you're scheduling events.
If you're scheduling an event to occur after the market opens, you might be using code similar to this:
In this example,
EveryDayAfterMarketOpenSPY
is a method that gets called 10 minutes after SPY opens every day. You might want to check that the symbols you're using in your scheduling rules are correct and that the securities are trading during the times you're scheduling events for.If you're still having issues, I would recommend posting your question on the QuantConnect Forum with a snippet of your code. The community there might be able to provide more specific help.
Sources:
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.
Conrad Krol
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!