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

...instance of an object error?

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

    ...instance of an object error?

    Greetings,

    I'm doing some testing and have this error, "Object reference not set to an instance of an object"...what does this log error mean? I believe it may be related to an array I have included:

    privatedouble[] Input;
    Input[0] = 22; Input[1] = 27.1; Input[2] = 31.9; Input[3] = 27; Input[4] = 12.3;
    Input[
    5] = 9; Input[6] = 12; Input[7] = 16; Input[8] = 17; Input[9] = 20;
    Input[
    10] = 22; Input[11] = 10; Input[12] = 13; Input[13] = 12; Input[14] = 3.1;
    Input[
    15] = 9; Input[16] = 21;

    Suggestions appreciated.

    #2
    This might help - http://www.ninjatrader-support.com/v...ead.php?t=4226
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks, is there any work-around that? I added the following:

      if(Input == null)
      {
      Input[0] = 22; Input[1] = 27.1; Input[2] = 31.9; Input[3] = 27; Input[4] = 12.3;
      Input[
      5] = 9; Input[6] = 12; Input[7] = 16; Input[8] = 17; Input[9] = 20
      ;
      Input[
      10] = 22; Input[11] = 10; Input[12] = 13; Input[13] = 12; Input[14] = 3.1
      ;
      Input[
      15] = 9; Input[16] = 21;

      }

      if(Input != null)
      {

      all OnBarUpdate stuff code in here

      }

      It removes the error and allows all periods in the backtest to cycle through, however nothing is being done...the code between the "if(Input != null)" brackets is being ignored...?
      Last edited by Burga1; 05-03-2008, 09:48 AM.

      Comment


        #4
        What's the difference between using an array like I have done and using a DataSeries? They seem identical in purpose...?

        Comment


          #5
          The main benefit of using a DataSeries object is that it is synchronized to the bars object.

          If nothing is being done inside your if-statement I suggest you try debugging it with Print commands before and inside the if-statement.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Thank you for the reply. I've de-constructed my code line-by-line and have determined the line that is throwing off an error. The log error is "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex"...I do not know what this error means and I have no variable with the name "startIndex" in my code. The line(s) in question causing this are:

            Print(Time[0].ToString()); Print("Current CurrentBar = " + CurrentBar);
            if(CurrentBar < 120){return;} // Make sure there are enough bars.

            AI_index =
            0;


            LOADER:

            //**CONVERT TO 1-100 PRICE SCALE
            value = Close[AI_index];
            String text = value.ToString();
            // TODO: validate that text is at least characters long to ensure Parse doesn't throw and exception.
            text = text.Substring(4);
            text=text.Insert(2, ".");
            value = double.Parse(text); INPUTS.Set(value);


            Specifically it is this line: text=text.Insert(2, ".");

            Any ideas what the problem with code may be? (NOTE: there is no other code currently in OnBarUpdate, I have removed all other lines and added them one by one to determine the line causing the error...).

            Comment


              #7
              The problem is that text likely does not have anything at index "2".
              RayNinjaTrader Customer Service

              Comment


                #8
                Thank you for the reply, I would probably agree with you except that this instrument is EUR/USD forex data only. Thus there must always be values carried at least that far, prices for that instrument carry out 4 positions (or even 5 with fractional pips enabled)...so I can't see how that could be the case...?

                Comment


                  #9
                  text.Length will return an integer value of the number of characters in your string.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, using the .Length command I see you are correct and there are values less than 2. I've removed the "Substring(4)" and the "Insert(2, ".")" commands and the correct values (Close prices) are now posting into "text".

                    I'm a bit confused as to how to best insert the "." however, playing around with it is not yielding the desired results. I simply want to convert the Close price (the "pips") into a 0-99.9 based scale, for example:

                    Close = 1.5496 converts to "96"
                    Close = 1.54962 converts to "96.2"
                    Close = 1.5500 converts to "0"
                    Close = 1.5517 converts to "17"
                    Close = 1.55334 converts to "33.4"

                    etc...anybody got an idea?

                    Comment


                      #11
                      Is there a command to "zero fill" the end of the Close price for a certain number of positions? I checked the MSDN site and couldn't find one, however I may have done an incorrect search...

                      Comment


                        #12
                        more math or string manipulation/formatting
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for your posts/help. I think I got that worked out now.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by elirion, Today, 01:36 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post elirion
                          by elirion
                           
                          Started by gentlebenthebear, Today, 01:30 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post gentlebenthebear  
                          Started by samish18, Yesterday, 08:31 AM
                          2 responses
                          9 views
                          0 likes
                          Last Post elirion
                          by elirion
                           
                          Started by Mestor, 03-10-2023, 01:50 AM
                          16 responses
                          391 views
                          0 likes
                          Last Post z.franck  
                          Started by rtwave, 04-12-2024, 09:30 AM
                          4 responses
                          34 views
                          0 likes
                          Last Post rtwave
                          by rtwave
                           
                          Working...
                          X