• 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

2 Conditions with different Bars.BarsSinceSession

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

  • NinjaTrader_PatrickH
    replied
    Hello wallsteetking,

    Thank you for your response.

    Are you looking for the session's open or the current bar's open? Open[0] would be the current bar's open.

    Setting the parameters to false will not resolve this matter. Can you provide a screenshot of your chart where the entries are made that should not be with your first example?

    I look forward to your response.

    Leave a comment:


  • wallsteetking
    replied
    Patrick, you are correct I am trying to check a condition on the first bar of the session and then a second condition in-between a specified number of bars. However, removing
    Code:
      protected override void OnBarUpdate()
            {
    			enterLongStrat1 = false;
    			enterLongStrat2 = false;
    Does not solve the problem. Here is proof. I changed the code just little bit where on, bar 1 close needs to be bigger then open by 4 ticks and on bar 7 the close needs to be also bigger than the open by 4 ticks. ( SEE BLUE CODE)
    Code:
     #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
    		private bool enterLongStrat1 = false;
    		private bool enterLongStrat2 = false;
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                SetProfitTarget("", CalculationMode.Ticks, 4);
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
    	     if (Bars.BarsSinceSession == 1)
                if (Close[0] >= Open[0] + 4 * TickSize)
                   {
             	 enterLongStrat1 = true;
    		}
    		
    		//  Condition set 2
    		if (Bars.BarsSinceSession == 7)
    		if (Close[0] >= Open[0] + 4 * TickSize)
    		 {
    			enterLongStrat2 = true;
    		}
    
                   // tally up 
    if (Bars.BarsSinceSession == 10 && enterLongStrat1 == true && enterLongStrat2 == true)
    			{    
      				EnterLong(DefaultQuantity, "");
    			}	
            }
    however, it just takes a long on the 10th bar Always
    I also tried,

    Code:
    #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
    		private bool enterLongStrat1 = false;
    		private bool enterLongStrat2 = false;
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                SetProfitTarget("", CalculationMode.Ticks, 4);
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
    	     if (Bars.BarsSinceSession == 1)
                if (Close[0] >= Open[0] + 4 * TickSize)
                   {
             	 enterLongStrat1 = true;
                     enterLongStrat2 = false;
    		}
    		
    		//  Condition set 2
    		if (Bars.BarsSinceSession == 7)
    		if (Close[0] >= Open[0] + 4 * TickSize)
    		 {
    			enterLongStrat2 = true;
                            enterLongStrat1 = false;
    		}
    
                   // tally up 
    if (Bars.BarsSinceSession == 10 && enterLongStrat1 == true && enterLongStrat2 == true)
    			{    
      				EnterLong(DefaultQuantity, "");
    			}
    Attached Files

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    Hello wallsteetking,

    Thank you for your note.

    I believe you are trying to check a condition on the first bar of the session and then a second condition in-between a specified number of bars. If this is correct, the reason it does not work is the that the two bools are reset to false on each bar update:
    Code:
            protected override void OnBarUpdate()
            {
    			enterLongStrat1 = false;
    			enterLongStrat2 = false;
    Please comment out these two lines and advise if this resolves the matter.

    Leave a comment:


  • 2 Conditions with different Bars.BarsSinceSession

    Hey Ninjatrader team

    How can I tell ninjatrader to allow two different conditions with different Bars.BarsSinceSession rules. to add more info I want to be able to create two booleans and have different Bars.BarsSinceSession inside the code. (for strategy)

    This is what I have right now. please explain how/why this does not work and how to fix it.

    Code:
     #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
    		private bool enterLongStrat1 = false;
    		private bool enterLongStrat2 = false;
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any                            strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                SetProfitTarget("", CalculationMode.Ticks, 4);
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			enterLongStrat1 = false;
    			enterLongStrat2 = false;
    		
                // Condition set 1
    	                if (Bars.BarsSinceSession >=50)
    			if (Bars.BarsSinceSession <=84)
                            if (Close[0] >= EMA(20)[0]
                                && Close[0] >= EMA(50)[0])	
                {
              	    //  enterLongStrat2 = true;
             	  	enterLongStrat1 = true;
                }
    		
    			//  Condition set 2
    			if (Bars.BarsSinceSession == 1)
    			if (Close[0] >= Open[0] + 4 * TickSize)
    			 {
    				enterLongStrat2 = true;
           		             // enterLongStrat1 = false;
    			}
    
    			if (enterLongStrat2 == true && enterLongStrat1 == true)
    			{    
      				EnterLong(DefaultQuantity, "");
    			}	
            }

Latest Posts

Collapse

Topics Statistics Last Post
Started by junkone, Today, 09:06 PM
0 responses
1 view
0 likes
Last Post junkone
by junkone
 
Started by marcelodelta, Today, 08:28 PM
0 responses
3 views
0 likes
Last Post marcelodelta  
Started by ferenc., Today, 04:54 PM
1 response
13 views
0 likes
Last Post NinjaTrader_EricB  
Started by rwilliam, Today, 03:51 PM
1 response
12 views
0 likes
Last Post NinjaTrader_ShawnB  
Started by RB104, Today, 02:37 PM
2 responses
26 views
0 likes
Last Post RB104
by RB104
 
Working...
X