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
    	   [B][COLOR="Blue"]  if (Bars.BarsSinceSession == 1)[/COLOR][/B]
                if (Close[0] >= Open[0] + 4 * TickSize)
                   {
             	 enterLongStrat1 = true;
    		}
    		
    		//  Condition set 2
    		[B][COLOR="blue"]if (Bars.BarsSinceSession == 7)[/COLOR][/B]
    		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
    	   [B][COLOR="Blue"]  if (Bars.BarsSinceSession == 1)[/COLOR][/B]
                if (Close[0] >= Open[0] + 4 * TickSize)
                   {
             	 enterLongStrat1 = true;
                    [B][COLOR="red"] enterLongStrat2 = false;[/COLOR][/B]
    		}
    		
    		//  Condition set 2
    		[B][COLOR="blue"]if (Bars.BarsSinceSession == 7)[/COLOR][/B]
    		if (Close[0] >= Open[0] + 4 * TickSize)
    		 {
    			enterLongStrat2 = true;
                            [B][COLOR="Red"]enterLongStrat1 = false;[/COLOR][/B]
    		}
    
                   // 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
    	               [B][COLOR="Blue"] if (Bars.BarsSinceSession >=50)
    			if (Bars.BarsSinceSession <=84)[/COLOR][/B]
                            if (Close[0] >= EMA(20)[0]
                                && Close[0] >= EMA(50)[0])	
                {
              	    //  enterLongStrat2 = true;
             	  	enterLongStrat1 = true;
                }
    		
    			//  Condition set 2
    			[B][COLOR="Blue"]if (Bars.BarsSinceSession == 1)[/COLOR][/B]
    			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 Perr0Grande, Today, 08:16 PM
0 responses
2 views
0 likes
Last Post Perr0Grande  
Started by elderan, Today, 08:03 PM
0 responses
5 views
0 likes
Last Post elderan
by elderan
 
Started by algospoke, Today, 06:40 PM
0 responses
10 views
0 likes
Last Post algospoke  
Started by maybeimnotrader, Today, 05:46 PM
0 responses
12 views
0 likes
Last Post maybeimnotrader  
Started by quantismo, Today, 05:13 PM
0 responses
7 views
0 likes
Last Post quantismo  
Working...
X