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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        66 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        41 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        24 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        27 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        53 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X