Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Instrument OnStartUp() Problem

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

    Multi Instrument OnStartUp() Problem

    Hi,

    I have a UserDefinedMethod called DoPrint which essentially does Print with a timestamp, instrument and a model identifier tag.

    In OnStartUp, I have included one of these DoPrints, which call Times[0][0] (to get the timestamp). In a single instrument/TF strategy, this works fine and the strategy performs as normal.

    However, when I add another instrument or TF and try running/backtesting the strategy, I get this error:

    **NT** Error on calling 'OnStartUp' method for strategy 'FW/e4d9e5b45b0746a8a04b5cf1bda2ebcf': Bar index needs to be greater/equal 0

    I have troubleshooted and found that the problem lies with Times[0][0]. If I do not use my DoPrint method or if I use a modified DoPrint method which doesn't include Times[0][0], it works fine. I have even tried several iterations of BarsInProgress with no luck.

    In this case, having the time of a bar printed OnStartUp is not relevant, and I could get around this problem by hardcoding a Print(ModelID + " Message") into the strategy instead so it is not a major problem. However, I am just interested to know why this is the case for only multi instrument strategies or if there is another workaround possible so that I can continue to use my DoPrint method for consistency?

    Thanks

    #2
    Hello wuileng,

    Do you pass a "BarsArray" or "BarsInProgress" value to your "DoPrints"?

    The error message is saying you are passing an invalid bar index. Note this can also be if your are using a single series item when it requires a multiseries item like "BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)".
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      I'm not passing either, the only thing bar dependent in DoPrint is Times[0][0].

      Also DoPrint is a single lined function which is passed two strings - contents and ModelID and does:
      Print (Times[0][0].ToString("HH:mm:ss") + ModelID + contents);

      Thanks again for your help.

      Comment


        #4
        Hello wuileng,

        Thanks for the information. Do you mind sharing the snippet of your strategy from your Initialize and OnStartUp() method to replicate the error for me to review?
        JCNinjaTrader Customer Service

        Comment


          #5
          Hi,

          I've replicated the problem.

          Code:
                  protected override void Initialize()
                  {
          			Add("SPY", BarsPeriods[0].Id, BarsPeriods[0].Value);
          			
          			BarsRequired = 0;
                  }
          		
          		protected override void OnStartUp()
          		{
          			// Print(Times[0][0].ToString("HH:mm:ss") + " - Test");
          			 Print(" - Test");
          		}
          It seems that if you set BarsRequired != 0 then there is no problem using Times[0][0] in OnStartUp() with multiple instruments. Otherwise, using Times[0][0] in OnStartUp() seems to cause this error.

          Thanks

          Comment


            #6
            wuileng, which instruments are you working with as this happens? I just tried ES 12-13 primary and your SPY added in and could not reproduce. The bars array info should be accessible, however the BIP reported for OnStartUp() would always be primary only.

            Comment


              #7
              Oh, I was using SPY and VXX, though I think you would see the error for any instrument.

              Did you uncomment the Print line which uses Times[0][0]?

              Comment


                #8
                Yes, I did, was using this print here to check into matters -

                protected override void OnStartUp()
                {
                Print(BarsInProgress + " BIP " + Times[1][0].ToString("HH:mm:ss") + " - Test Time 0 " + " " + Times[1][0].ToString("HH:mm:ss") + " - Test Time 1");
                }


                So VXX being primary then? Which timeframe and sessions were you using?

                Comment


                  #9
                  Ok I just played with it again, with VXX, GLD and several other US ETFs which are set to US Equities RTH session and based on 1 minute bars. These are the primary instruments whilst SPY is secondary.

                  Strangely enough, when I used your print, there isn't a problem. However, when I switch your Times[1][0] to Times[0][0], then the problem resurfaces.

                  Also, there isn't a problem using Times[0][0] when I select the primary instrument to be a futures contract (I tried the ES continuous contract).

                  Thanks

                  Comment


                    #10
                    Which data provider do you use wuileng? Tried with Time[0], Times[0] and Times[1] on Kinetick VXX and GLD as primary on US Index RTH and getting the expected prints shown. You are on latest NT7 R17 as this occurs, correct?

                    Comment


                      #11
                      I am also using Kinetick, and have tried different date ranges just in case this might be the problem.

                      I am on NT7 R16. Let me update now and see if this fixes it.

                      Edit: Seems like R16 is the latest, did you mean that?

                      Comment


                        #12
                        Originally posted by wuileng View Post
                        Hi,

                        I've replicated the problem.

                        Code:
                                protected override void Initialize()
                                {
                                    Add("SPY", BarsPeriods[0].Id, BarsPeriods[0].Value);
                                    
                                    BarsRequired = 0;
                                }
                                
                                protected override void OnStartUp()
                                {
                                    // Print(Times[0][0].ToString("HH:mm:ss") + " - Test");
                                     Print(" - Test");
                                }
                        It seems that if you set BarsRequired != 0 then there is no problem using Times[0][0] in OnStartUp() with multiple instruments. Otherwise, using Times[0][0] in OnStartUp() seems to cause this error.

                        Thanks
                        BarsRequired = 0; would imply you do not need any bars on the chart. Try using BarsRequired = 1;, meaning that you need at least one bar on the chart.

                        It has been my experience that using BarsRequired = 0; has always given me somewhat unpredictable problems; sometimes working perfectly, at other times producing out of range errors, that are hard to isolate.
                        Last edited by koganam; 11-19-2013, 04:44 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        666 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        377 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        110 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        575 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        580 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X