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 herzogvladimir2, Yesterday, 08:10 PM
            0 responses
            15 views
            0 likes
            Last Post herzogvladimir2  
            Started by giogio1, 04-13-2025, 01:42 AM
            2 responses
            39 views
            0 likes
            Last Post giogio1
            by giogio1
             
            Started by mmenigma, 01-23-2024, 09:37 AM
            1 response
            92 views
            0 likes
            Last Post Nin8aTrender  
            Started by wbayne333, 02-22-2021, 01:18 PM
            6 responses
            416 views
            0 likes
            Last Post Nin8aTrender  
            Started by gtheaded, 07-03-2020, 03:47 PM
            3 responses
            374 views
            0 likes
            Last Post Nin8aTrender  
            Working...
            X