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

Help with syntax- ArrayList-Struct

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

    Help with syntax- ArrayList-Struct

    I am trying to build an ArrayList (Rectangles) containing a structure (Reclh). Do we have to define the element type in ArrayList? It appears to me that ArrayList doesn’t accept a structure as it’s element. I get an xmlinclude error message.
    I referring to MS website but could not get much help. Can guide me if some one has a sample strategy that utilizes Lists and structures.

    using System.Collections;
    privateint barNo = 1;
    // User defined Structure to store point
    publicstruct Reclh { publicdouble l; publicdouble h;}
    // Arraylist by name "Rectangles" to store above structure
    public ArrayList Rectangles = new ArrayList();


    protectedoverridevoid OnBarUpdate()
    { Reclh Recoor; int mycon =0;
    while ( mycon < 5)
    { Recoor.l=mycon; Recoor.h=mycon+1; Print(mycon);
    Rectangles.Add(Recoor); // it error comes here
    ++mycon;
    }

    }

    As always any comment is highly appreciated.

    #2
    malmaa, unfortunately this is outside of the scope we can support here, but perhaps this will help you - http://www.daniweb.com/forums/thread70429.html#
    BertrandNinjaTrader Customer Service

    Comment


      #3
      malmaa,

      The beauty of c# is that everything is an object.

      So, you can create an ArrayList(), and add any object type to you. You simply need to properly cast it when you retrieve it from the ArrayList.

      Try this.

      Code:
      public struct Reclh
      {
          public double l;
          public double h;
      }
      
      private ArrayList al;
      
      protected override void Initialize()
      {
          al = new ArrayList();
      }
      
      protected override void OnBarUpdate()
      {
      
          Rectlh tRectlh;
      
          tRectlh.l = 1;
          tRectlh.h = 2;
      
          //Add this object to the arraylist
          al.Add(tRectlh);
      
      }
      Now, when you want to remove it just index it like an array. Be sure not to index past the bounds of the ArrayList(), which can be accessed with the .Count variable.

      Hope this helps.
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Fantastic!!
        I have been struggling for this info since last 3 days. You are a have given me sparkles for this New Year.
        Wish mrlogik and Ninja Team a Happy and Prosperous New Year.
        Thanks a lot.

        Comment


          #5
          you as well
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          16 responses
          3,279 views
          0 likes
          Last Post Leafcutter  
          Started by WHICKED, Today, 12:45 PM
          2 responses
          19 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by Tim-c, Today, 02:10 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          5 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          51 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X