Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the bar index of list's items?

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

    #16
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello PaulMohn,

    "How to get the index?"

    This is up to you. Why are you using an index with a List object?

    This is your logic. There must be a reason you want an index in the first place. There must be a value you have added to the List you want some information from.

    But I would not be able to tell you why you are wanting information saved in this list.

    What information is being saved in the list?

    What specific element in the list are you looking for and what index is it saved at?

    If you are trying to loop over the collection, the for loop parameters would be from 0 to 1 less than the size of the collection.

    "For for every timeframe/bar resolution/bar type?"

    I don't understand why you mentioning timeframe and bars. This is a List object and not related to bars or series data.
    Checking the index is less than the size of the List will prevent an invalid index no matter what bar type is it is not related to bar type at all.
    This is a List<t> not a Series<T>.
    How to use IndexOf() to solve this?
    ref. https://stackoverflow.com/a/13755053/10789707

    Or/and

    How to use FindIndex() to solve this?
    ref. https://stackoverflow.com/a/1568608/10789707​



    ref.
    https://stackoverflow.com/a/26641799/10789707
    Last edited by PaulMohn; 09-25-2024, 06:52 AM.

    Comment


      #17
      Hello PaulMohn,

      "How to use IndexOf() to solve this?"

      What are you trying to solve?

      If you have a value and are trying to find it in the list you can use IndexOf to get the index of that element.

      myList.IndexOf(myValue)

      However, this doesn't appear to be related to this thread. This thread was originally about ensuring an index used is less than the size of the collection. For series that would be CurrentBar for a list or array this would be .Count().
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        NinjaTrader_ChelseaB,

        Hello,

        Will you make a similar video to this one on CurrentBar and indexing errors:


        This too from 27:25 would help:
        Last edited by PaulMohn; 10-04-2024, 08:42 AM.

        Comment


          #19
          Hello PaulMohn,

          We will consider this for a future video.

          Thank you for the suggestion!
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20

            if (startBar<0)
            count += startbar;

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            72 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X