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

Generic List - Count (where)

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

    Generic List - Count (where)

    All,

    Hoping some of the senior members may be able to assist...

    I've a generic list populated by doubles each bound between 0 & 1. To map the distribution of elements between 0 & 1, I'm trying to count the number of elements < 0.1, then count the number of elements < 0.2, then < 0.3 etc.

    I originally thought the Count() method would be the way to go... but have no idea how to apply it to a single list.
    http://msdn.microsoft.com/en-us/library/bb535181.aspx

    As always any assistance would be appreciated.
    Regards
    Shannon

    #2
    Shannon, from a quick look - wouldn't FindAll be a start for your tasks?

    Retrieves all the elements that match the conditions defined by the specified predicate.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      Thanks for the solid guidance.

      Another question, a Count of the TheList.FindAll(item => item <= 0.5) yields the number of elements in the list that satisfy the requirement (item <= 0.5). Brilliant. And, as expected, TheList.Count is the total number of elements in The.List.

      I've tested these two parts separately, however, when combined to give the percentage of elements that satisfy the requirement (below) it all goes awry. It returns a zero or a one, as opposed to some number bound by zero and one.
      Code:
      TheList.FindAll(item => item <= 0.5).Count / TheList.Count
      As Always any ideas would be appreciated.
      Regards
      Shannon

      Comment


        #4
        Hi Shannon, I would tip on a division or precision issue here - could that be the case?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Your operands are integers: cast them to doubles first, before you do the division. Also check for a zero divisor.

          Comment


            #6
            koganam,

            You nailed it!
            The divisor was an integer. Cast to a double it works the treat.

            Thanks again
            Shannon

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X