• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

N Bar Up/Down

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

    N Bar Up/Down

    Hello,

    I'm new to strategy building. I've got a strategy built with an issue that i'm stuck on...

    Using N Bar Up/Down, I want to enter a position in the opposite direction once a certain number of consecutive bars are reached. (Example: buy after the 4th consecutive bar). The indicator triggers no problem with a 1 value that I can include in the strategy, but the problem is that it buys the 4th, 5th ,6th, 7th, etc consecutive bars also. So if im wrong and it goes past 4 to 8 consecutive bars, im wrong 4 times. How do I get the strategy to only buy the first bar after the N Bar (4) is triggered?? Screen shot attached.

    Any help is appreciated!

    JB
    Attached Files

    #2
    Hello justinbourque81,
    Thanks for your post.

    You could implement a counter or a switch to essentially turn on/off your conditions for entry. Something similar to the following snippet would count 4 'signal bars', place an entry on the following bar, and then reset the counter to zero.

    Code:
    private int counter = 0;
    protected override void OnBarUpdate()
    {
    	if (counter == 4)
    	{
    		//order entry here
    		counter = 0;
    	}
    	
    	if (counter < 4 && //your signal condition here//)
    	{
    		counter++;		
    	}
    
    }
    Please let me know if you have any questions.
    Last edited by NinjaTrader_JoshG; 04-02-2018, 08:00 AM.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for getting back to me. I am really new to this as I mentioned. Im sure this is painful for you to explain such easy stuff to a rookie haha. So what you provided for me is intended to be an addition to the N up/down bar one I have already built or the counter will replace the N up/down bar indicator i am using?? Thanks, JB

      Comment


        #4
        Hello justinbourque81,

        I see now that my sample was not as clear as it could have been. For most indicators my previous sample would be the correct way to accomplish this. I edited the original snippet to be more clear where your signal would go. After testing a little bit more; for the n Bars up/down indicators specifically it would be best to use the "switch" method though.
        This is because the nBars up/down indicator is already doing the counting for us.

        Code:
        private bool mySwitch = true;
        protected override void OnBarUpdate()
        {
        	double value = NBarsUp(4,true,true,true)[0];
        	if (value==0 && mySwitch == false) 
        	{
        		mySwitch = true;
        	}
        	
        	if (value==1 && mySwitch == true)
        	{
        		mySwitch = false;
        		Value[0] = value;
        	}
        }
        This snippet would only allow the first occurrence of NBarsUp after four consecutive up bars.

        Please let me know if you have any questions.
        Josh G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Dagamos, Today, 11:48 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Started by kantkant2, Yesterday, 03:20 PM
        4 responses
        24 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Started by EnveousColnago, Today, 11:50 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Skyfly1715, 01-20-2020, 03:36 PM
        4 responses
        33 views
        1 like
        Last Post eDanny
        by eDanny
         
        Started by Cyanez, Yesterday, 05:05 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X