• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Sulfred, Today, 12:34 AM
          2 responses
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by CopyPasteGhost, Today, 11:22 AM
          0 responses
          1 view
          0 likes
          Last Post CopyPasteGhost  
          Started by 1001111, Today, 10:23 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_PaulG  
          Started by NinjaCustomer, Today, 11:07 AM
          0 responses
          4 views
          0 likes
          Last Post NinjaCustomer  
          Started by NtFan, Today, 10:47 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X