Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

COT Percentile Rank (for loop?)

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

    COT Percentile Rank (for loop?)

    I am trying to create an indicator that transforms the current COT report positions into a percentile rank.

    One way to do this is using MAX and MIN but if I want to compare it to every position over n weeks would the best way to accomplish this be to use a for loop?
    Or is a for loop not the best process?

    I've been reading other forum posts on for loops but am having a little trouble on the for loop syntax in order to compare COT positions.

    I am only interested in comparing the current commercial position to its historical positions.

    Commercials[0] = COT(2).Cot2[0]; //current commercial position

    if I want to for loop to determine percentile rank:


    for (initializer; condition; iterator)
    {
    //code block
    }

    for (i=0; i >Commercials[0]; i++)
    {
    Commercials[i]
    }

    I am confused how to get the count for number of times the commercial position is greater or less.

    Thanks so much for the help.

    #2
    I figured it out thanks

    Comment


      #3
      Hello mlprice12,

      I'm glad you were able to figure it out. I'm not certain on what you are asking.

      The COT has 5 plots. Are you trying to compare the plots with each other?

      if (COT(2).Cot[2] > COT(2).Cot[3])
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for checking in Chelsea.

        I used the following code to create a percentile rank of a single COT plot over the lookback period.
        Code:
        if (CurrentBar == 1)
        {
        int rankPeriod = CurrentBar; 
        
        }
        if (CurrentBar > 0)
        {
        int weeksAgo = CurrentBar;
        Commercials[0] = COT(2).Cot2[0];
        double rank = 0.0;
        for (int i = 1; i <= weeksAgo; i++)
        if(Commercials[0] > Commercials[i])
        rank = rank + 1.0;
        COTPercentile[0] = 100 * rank/weeksAgo;
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        57 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        78 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        39 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        101 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        61 views
        0 likes
        Last Post PaulMohn  
        Working...
        X