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

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 terofs, Yesterday, 04:18 PM
            1 response
            21 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by CommonWhale, Today, 09:55 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by Gerik, Today, 09:40 AM
            2 responses
            7 views
            0 likes
            Last Post Gerik
            by Gerik
             
            Started by RookieTrader, Today, 09:37 AM
            2 responses
            12 views
            0 likes
            Last Post RookieTrader  
            Started by alifarahani, Today, 09:40 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X