public void AddIntervalWhileRunning() { OHLCBarStream blt = new OHLCBarStream(new ForexSecurity("TST")); blt.AddInterval(BarInterval.Minute); blt.AddInterval(BarInterval.FiveMin); blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar); Tick[] tape = TestBarList.SampleData(); blt.Initialize(); // add ticks from tape to tracker for (int i = 0; i < tape.Length; i++) { blt.GotTick(tape[i]); if (i == 1) { blt.AddInterval(120); } } //make sure we got one symbol as bar events Assert.Equal(1, syms.Count); // make sure our symbols matched barlist count Assert.Equal(blt.SymbolCount, syms.Count); // make sure same on individual bars Assert.True(blt[120].Count > 0); }
public void IntervalRequestDuringRun() { OHLCBarStream blt = new OHLCBarStream(new ForexSecurity("TST")); blt.AddInterval(BarInterval.FiveMin); blt.GotNewBar += new SymBarIntervalDelegate(blt_GotNewBar); Tick[] tape = TestBarList.SampleData(); blt.Initialize(); // add ticks from tape to tracker for (int i = 0; i < tape.Length; i++) { blt.GotTick(tape[i]); var value = blt[BarInterval.Minute].RecentBar; } // Check if the data differs per interval Assert.NotEqual(blt[BarInterval.Minute][-2].Close, blt[BarInterval.FiveMin][-2].Close); }
private static PortfolioManager Get(string symbol) { //Initialize TradingPortfolio np = new TradingPortfolio(); //ADD INITIAL SECURITIES ForexSecurity security = new ForexSecurity(symbol); security.LotSize = 100000; //Lots security.PipSize = 0.0001M; //PipSize in 4 decimal places security.TickSize = 0.00001M; //Size of one tick security.PipValue = 1M; //PipValue, if unable to calculate to base currency security.Digits = 5; var account = new SimAccount("SIMULATED", "Sim account for backtesting", 10000, 100, "SIM"); np.SetAccount(account); np.Securities.AddSecurity(security); //ADD AGENT AND INJECT TEMPLATES np.InjectAgent <ExampleTradingAgent>(); //Set streams TradingAgent agent = (TradingAgent)np.Agents[0]; agent.AgentId = 115230; agent.TimeFrame = TimeSpan.FromSeconds(TimeFrameInSeconds); OHLCBarStream ls = new OHLCBarStream(np.Securities[symbol], np.Agents[0].TimeFrame); agent.SetDefaultStream(ls); ls.Initialize(); agent.Initialize(); agent.Start(); SimpleBacktester.OnMessage += SimpleBacktester_OnMessage; SimpleBacktester.OnProgress += SimpleBacktester_OnProgress; return(np); }