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 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 lorem, Yesterday, 09:18 AM
          4 responses
          14 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by Spiderbird, Today, 12:15 PM
          0 responses
          5 views
          0 likes
          Last Post Spiderbird  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          12 responses
          42 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by FrazMann, Today, 11:21 AM
          0 responses
          6 views
          0 likes
          Last Post FrazMann  
          Started by geddyisodin, Yesterday, 05:20 AM
          8 responses
          52 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X