Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

index was out of bounds

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

    index was out of bounds

    Hi:

    I am adding a 3rd index on the bararray (I already have 2 that works perfectly). When I add the 3rd I get this error: index was out of bounds of the array?

    What would be causing it?

    #2
    Originally posted by birdog View Post
    Hi:

    I am adding a 3rd index on the bararray (I already have 2 that works perfectly). When I add the 3rd I get this error: index was out of bounds of the array?

    What would be causing it?
    Depends on how you are adding it, and how you are referencing it. It is hard to say without seeing some code.

    Comment


      #3
      Hello birdog,

      Thank you for your post.

      Have you added the third object in the code? (i.e Add())

      What is the exact code used with the BarsArray? Please detail in your response.

      I look forward to your response.

      Comment


        #4
        Hey Koganam:

        Ok...sure...here is the initialize (I have the 60 Minute disabled just so you know...it works fine with the Day and Week on but when I add the 4 hour I get a the error):

        Code:
        // Index 0 is the primary bars selected upon startup-Index 1 is Daily-Index 2 is Weekly-
                    // Index 3 is 60 Minute (hourly)-Index 4 is 240 Minute (4 hour).
                    // Add 1 Day (Daily) Bars object to the strategy
                    Add(PeriodType.Day, 1);
                    
                    // Add 1 Week (Weekly) Bars object to the strategy
                    Add(PeriodType.Week, 1);
                    
                    // Add 60 Minute (aka hourly)Bars object to the strategy
                    //Add(PeriodType.Minute, 60);
                    
                    // Add 240 Minute (aka 4 hour) Bars Bars object to the strategy
                    Add(PeriodType.Minute, 240);
        Here is onbarupdate:

        if (CrossAbove(SMA(Fast), SMA(Slow), 1)
        && x < myTradeCounter
        && (EMA(BarsArray[1], 1)[0] > EMA(BarsArray[1], 3)[0]
        && EMA(BarsArray[2], 1)[0] > EMA(BarsArray[2], 3)[0]
        //&& EMA(BarsArray[3], 1)[0] > EMA(BarsArray[3], 3)[0]
        && EMA(BarsArray[4], 1)[0] > EMA(BarsArray[4], 3)[0]))

        Comment


          #5
          Hello birdog,

          Thank you for your response.

          You currently only have 3 PeriodTypes added in the code, yet you are referencing BarsArray[4].

          You need to change that to 3 rather 4, as you have commented out the other PeriodTypes in Initialize() and the BarsArray[3] in the OnBarUpdate().

          For example:
          Code:
          if (CrossAbove(SMA(Fast), SMA(Slow), 1)
          && x < myTradeCounter
          && (EMA(BarsArray[1], 1)[0] > EMA(BarsArray[1], 3)[0] 
          && EMA(BarsArray[2], 1)[0] > EMA(BarsArray[2], 3)[0]
          //&& EMA(BarsArray[3], 1)[0] > EMA(BarsArray[3], 3)[0]
          && EMA(BarsArray[3], 1)[0] > EMA(BarsArray[3], 3)[0]))
          Please let me know if you have any questions.

          Comment


            #6
            ahhh...just fired up the coffee pot...hehehe...thanks Kog and Pat...

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DawnTreader, 05-08-2024, 05:58 PM
            10 responses
            38 views
            0 likes
            Last Post DawnTreader  
            Started by gaz0001, Today, 10:09 AM
            0 responses
            2 views
            0 likes
            Last Post gaz0001
            by gaz0001
             
            Started by proptradingshop, Today, 10:07 AM
            0 responses
            2 views
            0 likes
            Last Post proptradingshop  
            Started by franatas, Today, 09:49 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ZeroKuhl, Yesterday, 04:31 PM
            6 responses
            36 views
            0 likes
            Last Post ZeroKuhl  
            Working...
            X