Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Brevo, Today, 01:45 AM
        0 responses
        3 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        239 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        6 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X