Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

the use of IndexOf

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

    the use of IndexOf

    Hello,

    If i use Print("id"+newlist.IndexOf(df)); will it return the barIndex position or the IndexOf the bar position?

    Lets say id return 23 is it barIndex 23?


    Another question, is it possible to prevent a user from using my indicator at the same time as another. Suppose my indicator X is shown in the chart, is there a way to block other indicators like the SMA for example from being use at the same time?

    TY

    #2
    Hello frankduc,

    If i use Print("id"+newlist.IndexOf(df)); will it return the barIndex position or the IndexOf the bar position?
    You are using IndexOf on a list so it would return the index in that list if it is found, not a bar index. This is a C# method and not related to NinjaScript so the method will relate to what is in the collection you made.
    Returns the zero-based index of the first occurrence of a value in the List<T> or in a portion of it.




    Another question, is it possible to prevent a user from using my indicator at the same time as another. Suppose my indicator X is shown in the chart, is there a way to block other indicators like the SMA for example from being use at the same time?
    Not necessarily, to prevent another script from being used is not possible. You can stop your script from working based on variables but to base that on an indicator on the chart would only work sometimes. The load order of indicators is not guaranteed so its possible that sometimes the indicator could see other indicators and othertimes it won't. You would generally need to use a second panel if other indicators affect yours in some way instead of trying to prevent them from being used at the same time.

    I look forward to being of further assistance.





    Comment


      #3
      Jesse,

      Coming from the loop of a barIndex using chartfromindex to charttoindex that means if there is 1000 bars. IndexOf 0 will = 1000. Not good at all.
      I am looking for a method to get the value of a specific barIndex any suggestion?

      I want the index for all the values of my variables.
      variable df = value, how can i get the barIndex of that value?

      TY

      Comment


        #4
        Hello frankduc,

        Coming from the loop of a barIndex using chartfromindex to charttoindex that means if there is 1000 bars. IndexOf 0 will = 1000.
        IndexOf would not be used here, I am not sure what you are asking to do with IndexOf but it has no use with FromIndex and ToIndex.


        Not good at all.
        I am looking for a method to get the value of a specific barIndex any suggestion?
        FromIndex and ToIndex would be the range of indexs and then you would use the GetValueAt method with an index to get a value of a series. This is shown in the sample that you used to get FromIndex and ToIndex.


        I want the index for all the values of my variables.
        variable df = value, how can i get the barIndex of that value?
        This is taken out of context from your script so I don't know what you are asking to do here. If you are looking for a bar index and you used the loop we show in the help guide, you just use the index in that loop there is nothing else needed. The help guide shows how to get the bar index and also how you would get a value. https://ninjatrader.com/support/help...tsub=fromindex

        You don't need any other code to get the index of the bar with that sample and that index is directly used with the High to get its value.


        Please let me know if I may be of further assistance.


        Comment


          #5
          Jesse,

          I did not explain myself correctly.

          the variable df returns for example 1.42 from the code:

          Code:
          double df = newlist.Aggregate((x, y) => Math.Abs(x - fibo2) < Math.Abs(y - fibo2) ? x : y);
          As you can see df return a value from a list where the value is the closest from fibo2.

          But i have another list Aggregated that return values. But i want the value returned by the same barIndex for df.

          I guess there is no miracle method to do that.

          TY

          Comment


            #6
            Hello frankduc,

            There is not a NinjaScript method specific to what you are asking so you would likely need to use logic to solve this problem. Because you are using a C# list and general C# code there is not much I can suggest here. You would likely need to debug the script using Prints first to see what needs to change and locate logic that works for your goal. If you need to use the same index on both lists you may need to work out some other logic before you aggregate or do other actions to the list.



            Please let me know if I may be of further assistance.

            Comment

            Latest Posts

            Collapse

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