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

Working with generic lists

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

    Working with generic lists

    All,

    A plea for your programming knowledge...

    Lst<int> = a single-dimensional list (generic class)
    {1,2,3,4}
    MDLst<double> = a multi-dimensional list (generic class) where the first sub-element of each element corresponds to the elements of Lst. The first sub-element is a whole number (i.e. integer) but subsequent elements require doubles. (Apologies, if my vernacular is not correct)
    {1,x,x,x}
    {2,x,x,x}
    {3,x,x,x}
    {4,x,x,x}

    As new elements are added to Lst, or existing elements are removed from Lst, how would you go about implementing the same changes in MDLst?

    I imagine it would be something along the lines of (though the syntax escapes me):
    if Lst element does not exist in MDLst, then add new element to MDLst (i.e. new {y,x,x,x])
    if MDLst element no longer exists in Lst, then remove offending element from MDLst.



    As always, thanks and regards
    Shannon
    Last edited by Shansen; 09-11-2010, 08:33 PM.

    #2
    Shannon, sounds like you will have to create some sort of synchronization method to keep your lists all up to date.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin,

      Thanks for the quick reply.

      My programming knowledge is not sufficiently advanced to apply the synchronization method. I've implemented the below code (where MDLstAddition & MDLstRemoval = List<int> and Required = Boolean):
      Code:
            // Mark and add MDLst elements
            MDLstAddition.Clear();
            for (int i = 0; i < Lst.Count; i++) 
            {
              Required = true;
              double LstTest = Convert.ToDouble(Lst[i]);
              for (int j = 0; j < MDLst.Count; j++) 
              {
                if (LstTest == MDLst[j][0])
                  Required = false;
              }
              if (Required) 
                MDLstAddition.Add(i);
            }
            for (int i = 0; i < MDLstAddition.Count; i++) 
              MDLst.Insert(0, new List<double>(new double[]{Lst[MDLstAddition[i]],0,0,0,0}));
          
            // Mark and remove MDLst elements      
            MDLstRemoval.Clear();
            for (int i = 0; i < MDLst.Count; i++) 
            {
              if (!(Lst.Contains(Convert.ToInt32(MDLst[i][0]))))
                MDLstRemoval.Add(i);
            }
            for (int i = MDLstRemoval.Count; i > 0; i--) 
              MDLst.RemoveAt(MDLstRemoval[i-1]);

      Comments are welcome.
      Regards
      Shannon

      Comment


        #4
        Shannon, unfortunately I would not be aware of a readymade method for this scenrio, however you can look into ArrayList.Synchronize - http://msdn.microsoft.com/en-us/library/3azh197k.aspx (though I believe it only 'locks' a list to ensure nonconcurrent access).
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by samish18, Today, 10:13 AM
        0 responses
        2 views
        0 likes
        Last Post samish18  
        Started by kenz987, Yesterday, 10:20 AM
        2 responses
        13 views
        0 likes
        Last Post kenz987
        by kenz987
         
        Started by nicthe, 08-23-2023, 07:53 AM
        7 responses
        196 views
        0 likes
        Last Post nicthe
        by nicthe
         
        Started by nicthe, Today, 09:24 AM
        0 responses
        5 views
        0 likes
        Last Post nicthe
        by nicthe
         
        Started by stalt, 12-28-2015, 01:36 PM
        6 responses
        1,536 views
        0 likes
        Last Post giulyko00  
        Working...
        X