Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initialize a Series of Lists

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

    Initialize a Series of Lists

    Hello, just curious if there is an example of initializing a series of lists. I'd like to use a series of lists because i do not know how many elements are going to be computed in each bar. I found an example for creating and initializing a list (Initialize List) but for some reason I am unable to get it to work with a series of lists. Any help would be appreciated. Thanks!

    #2
    For example, private Series<List<double>> MySeries = new Series<List<double>>(); returns the error 'NinjaTrader.NinjaScript.Series<System.Collections .Generic.List<double>>' does not contain a constructor that takes 0 arguments.

    Comment


      #3
      Originally posted by Renorail View Post
      For example, private Series<List<double>> MySeries = new Series<List<double>>(this); returns the error 'NinjaTrader.NinjaScript.Series<System.Collections .Generic.List<double>>' does not contain a constructor that takes 0 arguments.
      Off the top of my head, looks like you need to break up
      the declaration, keep it separate from the initial assignment.

      Declare your variable, but do not initialize it (or initialize to null),

      Code:
      private Series<List<double>> MySeries = null;
      Initialize MySeries in OnStateChange, like this,

      Code:
      protected override void OnStateChange()
      {
          switch (State)
          {
              case State.SetDefaults:
                  MySeries = new Series<List<double>>(this);
                  break;
          ....
          }
      }

      Comment


        #4
        Thank you for your response and your help. I had that earlier too and could get it through compile but then get a " Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object. So, i thought it was an initialization issue.

        Maybe it is my .Add statement. I'll get a print before the assignment but not after.

        For testing purposes, i have the following:

        Code:
        private Series<List<double>> MySeries = null;
        Code:
        else if (State == State.DataLoaded)
        {
        MySeries =new Series<List<double>>(this);
        }
        My assignment that looks looks like:

        Code:
        double test_double = 4.3;
        MySeries[0].Add (test_double);
        Print(MySeries[0][0]);

        Comment


          #5
          Originally posted by Renorail View Post
          My assignment that looks looks like:

          Code:
          double test_double = 4.3;
          MySeries[0].Add (test_double);
          Print(MySeries[0][0]);
          That code is wrong.
          Do you want a Series of doubles?
          Do you want a Series of a list of doubles?

          Comment


            #6
            Hello Renorail,

            A new list would need to be instantiated for that bar.

            Code:
            MySeries[0] = new List<double>();
            double test_double = 4.3;
            MySeries[0].Add(test_double);
            Print(MySeries[0][0]);
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Perfect, thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by redart1021, Today, 10:29 AM
              0 responses
              1 view
              0 likes
              Last Post redart1021  
              Started by ervin, Today, 09:23 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by xxzbill, Today, 10:02 AM
              2 responses
              14 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by xxzbill, 08-19-2020, 11:06 PM
              4 responses
              32 views
              0 likes
              Last Post xxzbill
              by xxzbill
               
              Started by tonynt, Today, 09:39 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Working...
              X