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 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 Rapine Heihei, 04-23-2024, 07:51 PM
    2 responses
    30 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    943 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    9 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    4 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    28 views
    0 likes
    Last Post wzgy0920  
    Working...
    X