Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate how many bars within last 10 bars were above specific price.

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

    Calculate how many bars within last 10 bars were above specific price.

    My general idea is this:
    - 10 last bars
    - Current price is $4420.75
    - Specific price point is $4423.00

    - I visually see, that over last 10 bars, price (i.e. Low of the candle) was above specific price ($4423) 7 times.

    How to turn that into a calculation?

    #2
    Hello UltraNIX,

    Thanks for your question.

    You could use a for loop to loop over the current bar, 1 bar ago, 2 bars ago... 10 bars ago and check if the high of that bar is above your PRICE.

    Code:
    int myCount = 0;
    
    for (int i = 0; i < 10; i++)
    {
        if (Low[i] > PRICE)
            myCount++;
    }
    Print(myCount);
    Or starting from 9 bars ago, going to and including 0 bars ago:

    Code:
    int myCount = 0;
    
    for (int i = 9; i >= 0; i--)
    {
        if (Low[i] > PRICE)
            myCount++;
    }
    ​​​​​​​Print(myCount);
    myCount then represents the number of those bars from X number of bars ago where the Low is above PRICE.

    Let us know if there is anything else we can do to help.


    Comment


      #3
      Thanks, it worked!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      331 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
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      550 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X