Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

index was outside the bounds of array (newbie issue)

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

    index was outside the bounds of array (newbie issue)

    Hi guys,

    I get this error message when I use the following code could anyone help:
    I've tried debugging and haven't gotten anywhere.

    Thank you in advance and go easy on me .

    Code:
        public class ATRbands : Indicator
        {
            #region Variables
            // Wizard generated variables
                private bool chandemode = true;
                private int lookback_or_period = 14; // Default setting for Lookback_or_period
                private double maximumLength = 28; // Default setting for MaximumLength
                private double minimumLength = 7; // Default setting for MinimumLength
                private double ATRdev = 3.0;
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.RoyalBlue), PlotStyle.Line, "Upperline"));
                Add(new Plot(Color.FromKnownColor(KnownColor.RoyalBlue), PlotStyle.Line, "Lowerline"));
                CalculateOnBarClose = true;
                Overlay                = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                double highest_val = Math.Max(Math.Max(lookback_or_period, ATRdev) , Math.Max(maximumLength,minimumLength));
                
                if (CurrentBar < (int) highest_val)
                {
                    return;
                }
    
                double atr_len;
                double atr_val;
                
                if (chandemode == true)
                {
                    atr_len = ChandeATR(maximumLength, minimumLength,lookback_or_period)[0];
                    Print (atr_len);
                }
                else 
                {
                    atr_len = lookback_or_period;
                }
                
                atr_val = ATR( (int) atr_len)[0];
                
    //            Print(atr_len);
    //            Print(atr_val);
    //            Print(Close[0] + (atr_val * ATRdev));
                
                Upperline.Set(Close[0] + (atr_val * ATRdev));
                Lowerline.Set(Close[0] - (atr_val * ATRdev));
            }

    #2
    Hello jagtrading,

    Thank you for your post.

    Is there a difference of operating this script if you have 'chandemode' set to true or false?

    When you run this script with it set to true do you get the Print() for atr_len?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      ok I've changed my code a bit here since there were some errors but I'm still getting the same problem. I've made some changes to onbarupdate. Both true and false "iATR" returns values but than crashes.

      Code:
       
      protected override void OnBarUpdate()
              {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  double highest_val = Math.Max(Math.Max(lookback_or_period, ATRdev) , Math.Max(maximumLength,minimumLength));
                  
                  if (CurrentBar < (int) highest_val)
                  {
                      return;
                  }
                  
                  double iATR;
                  
                  if (chandemode == true)
                  {
                      iATR = ChandeATR(Close, maximumLength, minimumLength,lookback_or_period)[0];
                  }
                  else 
                  {
                      iATR = ATR(lookback_or_period)[0];
                  }
                  
                  Print(iATR);
                  Print(Close[0] + (iATR * ATRdev));
                  Print(Close[0] - (iATR * ATRdev));
              
                  
                  Upperline.Set(Close[0] + (iATR * ATRdev));
                  Lowerline.Set(Close[0] - (iATR * ATRdev));
              }

      Comment


        #4
        jagtrading,

        Please send me your log and trace files by going to Help -> Mail to Platrform Support

        Put Attn Cal in the subject and reference this thread in the body.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          ok i've done that.

          thanks for the support by the way guys.

          Comment

          Latest Posts

          Collapse

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