// Add Hundreds of Stock and Forex Symbol: public override void Initialize() { AllSymbols = new List <string>(); //Backtest period: SetStartDate(2014, 01, 01); SetEndDate(2015, 01, 01); //Set cash to 250k for test algorithm SetCash(250000); int count = 0; foreach (var symbol in StockSymbols) { AddSecurity(SecurityType.Equity, symbol, Resolution.Second, true); } foreach (var symbol in ForexSymbols) { AddSecurity(SecurityType.Forex, symbol, Resolution.Second, true); } AllSymbols = StockSymbols.Concat(ForexSymbols); }
public override void Initialize() { SetStartDate(2014, 01, 01); SetEndDate(2014, 02, 01); SetCash(250000); var allSymbols = StockSymbols.Concat(ForexSymbols).ToList(); var symbolsUsed = new HashSet <string>(); int totalSymbols = TickSymbolsToRun + SecondSymbolsToRun + MinuteSymbolsToRun; for (int i = 0; i < totalSymbols; i++) { Resolution resolution = Resolution.Tick; if (i >= TickSymbolsToRun && i < TickSymbolsToRun + SecondSymbolsToRun) { resolution = Resolution.Second; } else if (i >= TickSymbolsToRun + SecondSymbolsToRun) { resolution = Resolution.Minute; } string nextSymbol; do { nextSymbol = GetRandomItem(allSymbols); }while (!symbolsUsed.Add(nextSymbol)); SecurityType type = SecurityType.Equity; if (ForexSymbols.Contains(nextSymbol)) { type = SecurityType.Forex; } AddSecurity(type, nextSymbol, resolution); Debug("Added " + nextSymbol + " at " + resolution); } int ticks = SubscriptionManager.Subscriptions.Count(x => x.Resolution == Resolution.Tick); int seconds = SubscriptionManager.Subscriptions.Count(x => x.Resolution == Resolution.Second); int minutes = SubscriptionManager.Subscriptions.Count(x => x.Resolution == Resolution.Minute); Debug(string.Format("Ticks {0} Seconds {1} Minutes {2}", ticks, seconds, minutes)); }