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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X