Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NBarsUp 3 out of 5 were up?

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

    NBarsUp 3 out of 5 were up?

    Hello,

    I'm trying to figure out how to evaluate if any of the 3 of the bars in the last 5 were up with NBarsUp. Is that possible?


    In the Ninjascript instructions it says "Period" parameter is for: Number of bars used in the calculation but I don't see an example of this.


    Example is:
    Code:
    double value = NBarsUp(3, true, true, true)[0];
    I assume [0] is for the current time frame? If it were [1] it would check another timeframe if existed?

    #2
    Hello tickaway,

    Thank you for writing in.

    NBarsUp() does not take a period parameter. I will be reporting this so that period is removed from the help guide page for NBarsUp.

    The barsAgo value [0] is not referring to a time frame. A [0] would denote the current value of the indicator, [1] the previous value, [2] the second previous value, so on and so forth.

    I have created a simple example below to show how you can evaluate if at least 3 of the previous 5 bars were up bars. If this is true, draw a dot.

    Code:
    private int counter = 0;
    
    protected override void OnBarUpdate()
    {
    	if (CurrentBar < 5)
    		return;
    	
    	for (int i = 5; i > 0; i--)
    		if (Close[i] > Open[i])
    			counter++;
    
    	// if our counter variable is more than or equal to 3, this denotes we've had at least 3 up bars in that 5 bar period we were looking over
    	if (counter >= 3)
    		DrawDot("Dot" + CurrentBar, true, 0, Close[0], Color.Green);
    	
    	counter = 0;
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    580 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    335 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    102 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X