Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with Exit comands

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

    Problems with Exit comands

    Help please.
    Have code with 2 instruments NQ as main intrument + ES:
    Code:
    Add("ES 09-16", PeriodType.Minute, BarsPeriod.Value);
    Enter positions with:
    Code:
    if (Position.MarketPosition == MarketPosition.Flat &&
    								
    				(Closes[0][0] - EtN) > 0 &&
    				(Closes[0][0] - EtN) > 5		
    				)
    			{ 
    				if (BarsInProgress == 0)				
    				EnterShort(5, "NQ");						
    				
    				if (BarsInProgress == 1)
    				EnterLong(4, "ES");					
    			}
    And it's OK.
    I cant Exit them correctly:
    Code:
    if (BarsInProgress == 0)
    	{
            if (CrossBelow(XXXXX, 0, 1) || CrossAbove(XXXXX, 0, 1))
    				{	
    				//if (BarsInProgress == 0)
    				ExitLong("NQ");
    								
    				//if (BarsInProgress == 1)
    				ExitShort("NQ");
    					
    				}	
    	}
    			
    if (BarsInProgress == 1)
    	{
    	if (CrossBelow(XXXXXX, 0, 1) || CrossAbove(XXXXXX, 0, 1))
    				{
    				//if (BarsInProgress == 0)
    				ExitShort("ES");
    								
    				//if (BarsInProgress == 1)
    				ExitLong("ES");
    					
    				}
    	}
    Dont work.

    Code:
    if (BarsInProgress == 0)
    {
                                    if (CrossBelow(XXXXX, 0, 1) || CrossAbove(XXXXX, 0, 1))
    				{				
    				ExitLong();					
    				ExitShort();				
    				}	
    	}
    			
    if (BarsInProgress == 1)
    	{
    	if (CrossBelow(XXXXXX, 0, 1) || CrossAbove(XXXXXX, 0, 1))
    				{			
    				ExitShort();				
    				ExitLong();				
    				}
    	}
    Dont work.

    Noone Exits or 1 Exit and another is not.

    #2
    Hello iskip,

    Thank you for writing in.

    I want to note that your Exit methods need to be called on the same BarsInProgress of the instrument. You wouldn't be able to call an Exit method for the NQ when BarsInProgress is 1 as the NQ would be at BIP 0.

    To get around this, you'll want to use the Exit methods that accept a barsInProgressIndex parameter and enter the BarsInProgress index of the instrument you are trying to exit the position of.

    Code:
    ExitShort(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
    ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello iskip,

      Thank you for writing in.

      I want to note that your Exit methods need to be called on the same BarsInProgress of the instrument. You wouldn't be able to call an Exit method for the NQ when BarsInProgress is 1 as the NQ would be at BIP 0.

      To get around this, you'll want to use the Exit methods that accept a barsInProgressIndex parameter and enter the BarsInProgress index of the instrument you are trying to exit the position of.

      Code:
      ExitShort(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
      ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
      Please, let us know if we may be of further assistance.
      Do I correctly understand the code?
      Code:
      if (CrossBelow(EStoNQ(1).Plot0, 0, 1) || CrossAbove(EStoNQ(1).Plot0, 0, 1))
      							
      				{	
      				
      				ExitLong(0, 5, "",""); //for NQ with BIP = 0
      				ExitShort(0, 5, "","");				
      				
      				ExitLong(1, 4, "",""); //for ES BIP = 1 
      				ExitShort(1, 4, "","");
      					
      				}

      Comment


        #4
        Hello iskip,

        The sample you have provided will exit any open positions you have for both instruments if your condition is true.
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        117 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        166 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        85 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        130 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        88 views
        0 likes
        Last Post PaulMohn  
        Working...
        X