예제 #1
0
        /// <summary>
        /// Execute the on bar event for each new bar to be processed by the associated modules
        /// </summary>
        /// <param name="bar"></param>
        public void OnBar(Bar bar)
        {
            LocalLog(LogLevel.Trace, "OnBar: Processing bar Symbol: {0}, Interval: {1}", bar.Symbol, bar.CustomInterval);

            //Check for BackFilling
            IsBackfilling = BackFillingBars > 0;

            //Execute all OnBar events (Indicators first)
            if (string.IsNullOrWhiteSpace(bar.Symbol))
            {
                return;
            }
            DataStream stream = Portfolio.Streams[bar.Symbol];

            if (stream == null || stream.Security == null || stream.Security.Name != bar.Symbol)
            {
                LocalLog(LogLevel.Error, "Could not find stream for symbol {0}", bar.Symbol);
            }

            //Execute all OnBar events (Indicators)
            Exec.InvokeAll(_invokeOnBar, bar, stream, typeof(IndicatorModule), typeof(Indicators.IndicatorBase));

            //Execute all OnBar events (nonIndicators)
            Exec.InvokeAllExclude(_invokeOnBar, bar, typeof(IndicatorModule), typeof(Indicators.IndicatorBase));

            //check for main timeframe
            if (bar.CustomInterval != (int)TimeFrame.TotalSeconds)
            {
                LocalLog(LogLevel.Trace, "OnBar: Bar is discarded for agent calc events, expected interval: {0} but found interval: {1}", TimeFrame.TotalSeconds, bar.CustomInterval);
                return;
            }
            else
            {
                LocalLog(LogLevel.Trace, "OnBar: Bar is processed for agent calc event, found interval: {0}", bar.CustomInterval);
            }

            //Check all entry module logic
            ClearAgentSate();
            Exec.InvokeAll(OnCalcEvents, typeof(EntryModule));
            Entry();

            //Check all exit module logic
            ClearAgentSate();
            Exec.InvokeAll(OnCalcEvents, typeof(ExitModule));
            Exit();
        }
예제 #2
0
        //Test correct default behavior
        public void TestInvokeReturn_Default()
        {
            //Arrange
            List <InvokeLinkFunc <Bar, Tick, bool> > OnTest = new List <InvokeLinkFunc <Bar, Tick, bool> >();

            OnTest.Add(new InvokeLinkFunc <Bar, Tick, bool>()
            {
                ParmType       = typeof(Bar),
                Action         = TestOnMultipleReturn,
                BaseType       = typeof(TestReflectionInvoke),
                DataStreams    = new[] { _stream },
                ReturnType     = typeof(bool),
                SecondParmType = typeof(Tick)
            });

            //Act
            _sut.InvokeAll(OnTest, _bardata, _tickdata);

            //Assert
            _touchedbar.Should().BeTrue();
            _touchedtick.Should().BeTrue();
            OnTest.All(x => x.Result != null && x.Result == true).Should().BeTrue();
        }