Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem when work with Multi Instrument series

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem when work with Multi Instrument series

    We try work with multi series data. We add secondary instrument like this:
    Code:
     else if (State == State.Configure)
                {
                    AddDataSeries("SPY");​
    After in OnBarUpdate we check that all bars loaded and State of strategy. Like this:

    Code:
     protected override void OnBarUpdate()
            {
                if (BarsInProgress > 1)
                    return;
    
                if (CurrentBars[0] < FirstValidValue() || CurrentBars[1] < FirstValidValue() || CurrentBars[2] < FirstValidValue())
                    return;
    
                CalculateCurrentData();
                CPUpdateDataASync();
    
                if (State != State.Realtime)
                    return;
    
                lock (barUpdate)
                {
                    EntryEngine();
                    ExitEngine();
                }
            }​
    When we work in real-time quotes - all logic work fine.
    But when we download data for PlayBack - we have error - "ERROR: Strategy Error on calling 'OnBarUpdate' method on bar 1275: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    We can't debug with VS and found this error only in trace files.
    Please help understand why we have this error in PlayBack?

    #2
    CurrentBars[2] would be referring the CurrentBar of a SECOND AddDataSeries but you only have one, so it would crash immediately there.

    If you only have one AddDataSeries in State.Configure, you have CurrentBars[0] and CurrentBars[1] and anything beyond that is an invalid index.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Sorry, i don't show all serias that i added. A have all this series and it work fine when real quotes, have problem on playback connection only

      Comment


        #4
        Maybe you can help trace which line generate problem& When i in debug mode i don't catch any exceptions or crashes, strategy just shutdown without any information.

        Comment


          #5
          I would also be cautious about locking like you are doing there. If you are also locking in OnRender or in OnStateChange or OnMarketData or OnWhatever or in a timer there could be a possibility of introducing a deadlock - this can be done but you have to be very, very careful. That is not the problem you are reporting, but that is a potential future hazard lurking in the shadows there.

          Perhaps your FirstValidValue() is not returning a number that is large enough, or perhaps the index problem is in another part of your code.

          Turn on debug mode by right clicking then recompile, then, the next time it happens look at the trace file in Documents -> NinjaTrader 8 -> trace to see the line number of your error which will be contained in the stack trace.
          Last edited by QuantKey_Bruce; 04-24-2023, 07:03 AM.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Originally posted by QuantKey_Bruce View Post
            I would also be cautious about locking like you are doing there. If you are also locking in OnRender or in OnStateChange there could be a possibility of introducing a deadlock - this can be done but you have to be very, very careful.

            Perhaps your FirstValidValue() is not returning a number that is large enough, or perhaps the index problem is in another part of your code.

            Turn on debug mode by right clicking then recompile, then, the next time it happens look at the trace file to see the line number of your error which will be contained in the stack trace.

            Thanks about locking, i only block here in order to prevent parallel placing of orders if there is a tick on the main instrument and SPY at the same time, since there is some lag when working in conjunction with IB.

            About Debug mode it turned on, and when crach is happened i don't receive any exception, just shutdown strategy and on line in log file

            Comment


              #7
              Regarding there being a tick on the main instrument and another data series at the same time, it should not be possible to be in OnBarUpdate() in the same indicator instance with two different BarsInProgress at the same time because of the way indicator instances are assigned in the relevant thread pool. Please correct me if I am wrong about this, but architecturally, that does not sound like something that should be possible. It is certainly possible to be in OnBarUpdate and OnStateChange or OnBarUpdate and OnRender at the same time...
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                When you say one line in the log file, are you looking in "log" or in "trace"?
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  Hi tanas.eduard, thanks for posting. The market replay type data we supply is only available for Futures and Forex instrument types, there is a difference between Market Replay data and 1 tick historical data. You must have 1 tick data for the SPY downloaded and switch to "Historical" mode to access historical data while connected to the playback connection.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  52 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  70 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  48 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X