Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing lists to user defined methods

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

    Passing lists to user defined methods

    Hello

    I have no experience in C# programming.

    I want the user defined method below

    public void RO(List<double> b,List<double> r,int n)
    {
    int i;

    for (i=n;i>=0;i--)//load d reversed into r
    {
    r.Add(b[i]);
    }
    }

    to load the values in p into r but when RO is called, r.Count = 0 so I get an error message, "Accessing an index with a value that is out of range."

    How do I get r to have the same size as p?

    Regards

    Leon

    #2
    Do you know List<T>.Reverse() ?

    Comment


      #3
      Hello LeonPierre,

      You may want to check the b.Count and ensure that there are values there to add.

      With the looping and getting the out of index error, you are trying to get an index above the available count.

      I would do checks through your method to ensure that you have the valid data before moving to the loop.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        I do. But list.Count=0 giving an out of range error is a general problem I have with user defined methods so I must find a way to solve this.

        Comment


          #5
          Hello Cal

          There are values in b and I have checked b.Count but I still get the error message.

          Leon

          Comment


            #6
            Hello Leon,

            Are you checking the List objects in the Strategy or Indicator before you pass them into your method to make sure they are correct?
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            580 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            335 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            102 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X