Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NBarsUp

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

    NBarsUp

    I wanted to calculate the range of the indicator NBarsUp, but I dont know how to express the low of the first bar of the series. for example

    for (int i = 0; i < BarCount + 1; i++)
    {
    if (i == BarCount)
    {
    gotBars = true;
    break;
    }

    if (!(Close[i] > Close[i + 1]))
    break;

    if (BarUp && !(Close[i] > Open[i]))
    break;

    if (HigherHigh && !(High[i] > High[i + 1]))
    break;

    if (HigherLow && !(Low[i] > Low[i + 1]))
    break;
    }
    if(gotBars)
    Value.Set(Low[ " FIRST BAR OF NbarsUP ] + High[0]) ;

    }

    Not sure if you someone can help me with that coding line, or if you know of an existing indicator that does this range calculation of N bars Up.

    I appreciate your collaboration.

    #2
    BuhoTrader,

    One thing to be aware of :

    NBarsUp :

    Checks for n number of consecutive higher closes. Returns a value of 1 when the condition is true or 0 when false.

    This series only returns 1 and 0, so I am not sure how you mean you want to calculate the range of this indicator. Could you clarify?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Adam for your reply. What I was thinking of doing was changing the code of this indicator a little bit. What I am trying to do is great an indicator that will detect 3 or more consecutive bull candles and then calculate the range of that series of bars, by taking the low of the first Green bar and subtract the high of the last green bar of that series, wether there is 3 or 9 consecutive bars for example.

      So i changed the code of the NbarUp indicator since it does the first part of my logic. It finds 3 or more consecutive green candles.
      So i changed the original code of

      Value.Set(gotBars == true ? 1 : 0);

      for
      if(gotBars)
      Value.Se((High[0] - Low[2]);
      and it works fine as long as there are 3 bars, but when there are more than 3 it will only calculate the range of the last 3 green bars and I want the range of the whole consecutive green bars the NbarUp finds. So, if there are 5 consecutive bars, I want the high of the current green bar - the Low of 5 bas back(which will be the first green bar in the series of consecutive bars) . Does it make sense?

      Thanks again for taking the time to look into this.

      Comment


        #4
        BuhoTrader,

        I would probably do something like this (just as an example of consecutive green bars) :

        if ( Close[0] > Open[0] )
        {
        counter++;
        }
        else
        {
        counter = 0;
        }

        if ( counter >= 3 )
        {

        Value.Set((High[0] - Low[counter]);

        }
        else
        {

        Value.Set(default);

        }

        Let me know if I am not understanding correctly. It just looks a bit easier to me than using the NBarsUp, but there are multiple ways of doing this.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X