Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            656 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            371 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            579 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X