Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Number of Last consecutive Bars

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

    Number of Last consecutive Bars

    Hi,
    I am trying to get an indicator which shows the number of last consecutive up or down bars.
    I was not able to find any indicators that gives me this information. nbarsup and nbarsdown provides a 1 or 0 if the if the last n periods were in a trend.

    What I need is a numerical count for how many bars/ periods the candles have been the same color.
    If the candle 4 periods ago was green and the 3 more recent candles were all red, indicator should be -3.
    Then if the last six candles were all green, indicator equal 6

    Is this difficult to build?
    Can you please help?


    #2
    Hello horacioofman,

    I'm not certain there is an existing method that has that specific functionality and you will likely need to do this in a for loop.

    Starting at 0 bars ago (the current bar) to CurrentBar (the number of barsAgo to the first bar), compare if the index bar meets the criteria, if it does increment an integer as a counter, if it does not then break the loop.

    Code:
    int consecutiveBarsFound = 0;
    
    for (int index = 0; index < CurrentBar; index++)
    {
    if (Close[index] < Open[index]) // your condition here
    {
    consecutiveBarsFound++;
    }
    else 
    {
    break;
    }
    }
    
    Print(consecutiveBarsFound);
    Below is a link to a support article on looping.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      HI Chelsea,

      I managed to put together an indicator, but I am having a different issue now. I will open a different post for specifc problemshooting.

      Thanks for your help
      Attached Files
      Last edited by horacioofman; 11-03-2024, 01:20 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by sjsj2732, Today, 04:31 AM
      0 responses
      20 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      279 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      279 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      130 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      89 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X