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

How to create an array of Data Series objects

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

    How to create an array of Data Series objects

    An Array can store any type, including DataSeries objects.
    As an example, let's create an array to hold two DataSeries.

    Declare the array, and declare two DataSeries.

    Code:
    [FONT="Courier New"]private DataSeries [] sumSeries;[/FONT]
    [SIZE="2"] //the array named sumSeries that will contain DataSeries objects.[/SIZE]
    [FONT="Courier New"]private DataSeries ds0,ds1;
    [/FONT] [SIZE="2"]//the two DataSeries that will be held in the array[/SIZE]
    In the Initialize() method:
    Code:
    [FONT="Courier New"]ds0=new DataSeries(this);
    ds1=new DataSeries(this);			
    sumSeries  = new DataSeries[2];[/FONT] [SIZE="2"]// array of [I]length[/I] 2 defined, but at this point is empty[/SIZE] 
    [SIZE="3"]([B]length[/B] of array is the [I]number of elements it contains[/I])[/SIZE]
    [SIZE="2"]//now populate the array[/SIZE]
    [FONT="Courier New"]sumSeries[0]=ds0;           
    sumSeries[1]=ds1;[/FONT]
    That's it, we're done. Have a nice day.
    Last edited by Ricam; 01-14-2015, 04:32 AM.

    #2
    Thanks for the share Ricam, we appreciate it.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      An Array can store any type, including DataSeries objects.
      Once again, as an example, let's create an array to hold more than one DataSeries.
      However, there is an easier way to do it than I posted the first time, that also has a huge advantage: The length (number of elements) of the array does not need to be hard coded. It can be user selected or programmatically controlled, and the setting of the object references can be done in a For loop.

      Declare the array. At this point all we are doing is reserving some memory in which to place an array of DataSeries objects called multiSeries; the length (number of elements) is not yet defined and the array is empty.

      Code:
      [FONT="Courier New"]private DataSeries [] multiSeries;[/FONT]
      [SIZE="2"] //declare an array that will contain object references to DataSeries objects.[/SIZE]
      In the Initialize() method:
      Code:
      [SIZE="2"]//specify the number of elements in the array, which is the integer called [B][FONT="Courier New"]length[/FONT][/B] [/SIZE][FONT="Courier New"]
      multiSeries[]=new DataSeries[length];           
      [/FONT]
      [SIZE="2"]//the array now contains the number [B][FONT="Courier New"]length[/FONT][/B]  of object references that need to be set to instances of objects[/SIZE]
      [FONT="Courier New"]
      for (int count = 0; count<length; count++)
      multiSeries[count]=new DataSeries(this);           
      [/FONT]
      Code:
      [FONT="Courier New"]double value_X_BarsBack_of_multiSeriesN = multiSeries[N][X];Remember, an array is a ZERO BASED collection. So, for example, if an array contains 5 items, the subscripts of the items will be 0 through 4, not 1 through 5. Hence the start and end points of the For loop.
      
      Each of these objects is accessed like any other DataSeries, but don't forget the first subscript that tells you which one is being accessed.
      
      
      That's it, we're almost done for today. Have a nicer day.

      But before I return to my undisclosed location, here is an example of how to use this technique, based on the Freedom of Movement Indicator in the April 2014 issue of TASC. By eliminating dependencies on external classes, the performance of the indicator will be improved.[/FONT]
      Attached Files
      Last edited by Ricam; 01-14-2015, 04:30 AM.

      Comment


        #4
        revised posts about arrays of DataSeries

        The number of elements in an array is the LENGTH.

        The number of dimensions of an array, minus 1, is the RANK.

        Comment


          #5
          Excellent post!! can you please give some reference to where I can learn more about array and dataseries programming in NinjaTrader? Thanks

          Comment


            #6
            Sam, welcome to our forums - for our supported DataSeries objects I could point you those helpful reference samples -



            Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Max238, Today, 01:28 AM
            4 responses
            33 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by r68cervera, Today, 05:29 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by geddyisodin, Today, 05:20 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by timko, Today, 06:45 AM
            2 responses
            13 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by habeebft, Today, 07:27 AM
            0 responses
            6 views
            0 likes
            Last Post habeebft  
            Working...
            X