Hi,

I'm new to QuantConnect, coming over from Quantopian. I'm trying to build a day-trading algorithm that's focused on top gainers from the top 500 dollar-volume stocks. From what I gathered from documentation and forums, I tried to start with the top-500-dollar-volume universe, check the price at open versus yesterday's close, and wittle down to the top 10 gainers to monitor for certain triggers for the rest of the day. Below is the code I have so far. The problem is that, unfortunately, the backtest is always timing out. I haven't dug deep in LEAN's code-base, and it's hard to debug since if I use VS offline I can't get data, and there's no online debugging capabilities at the moment; so my best guess is that it's timing out because it's still trying to stream data to all 500 stocks and that's obviously causing it to time out. I even tried to manually manage the equities (via RemoveSecurity, Securities.Remove, even through UniverseManager) but it still times out (I haven't included that code so as to start from a simpler code here, but I can share as well).

Any thoughts or ideas?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using QuantConnect.Data; using QuantConnect.Data.Market; using System.Diagnostics; namespace QuantConnect.Algorithm.CSharp { class Quantithmar : QCAlgorithm { //private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA); private int _universeSize = 500, _trackerCount = 10; private IEnumerable<QuantConnect.Securities.Security> _dailyTrackers = new List<QuantConnect.Securities.Security>(); /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { SetCash(100000); SetStartDate(2017, 08, 01); Schedule.On(DateRules.EveryDay(), TimeRules.At(9, 31), SelectStocks); //SetRunMode(RunMode.Parallel); UniverseSettings.Resolution = Resolution.Minute; AddUniverse(Universe.DollarVolume.Top(_universeSize)); } private void SelectStocks() { try { Debug(Time.ToString()); Dictionary<QuantConnect.Securities.Security, decimal> changes = new Dictionary<QuantConnect.Securities.Security, decimal>(); IEnumerable<Slice> slices = History(TimeSpan.FromDays(1), Resolution.Daily); foreach (var s in Securities) { if (slices.Count() > 0 && s.Value.Price > 0) { IEnumerable<decimal> closingPrices = slices.Get(s.Value.Symbol, Field.Close); var change = (s.Value.Price - closingPrices.FirstOrDefault()) / s.Value.Price; changes.Add(s.Value, change); } } if (changes.Count > 0) { _dailyTrackers = changes.OrderBy(x => x.Value).Take(_trackerCount).Select(x => x.Key); var msg = ""; foreach (var s in _dailyTrackers) msg += s.Symbol.Value + ", "; Debug(msg.Substring(0,msg.Length-2)); } } catch (Exception ex) { Debug(ex.ToString()); } } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">Slice object keyed by symbol containing the stock data</param> public override void OnData(Slice data) { if (!Portfolio.Invested) { } } } }