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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      140 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X