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 inanazsocial, Today, 01:15 AM
        0 responses
        2 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        10 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        71 views
        0 likes
        Last Post jeronymite  
        Working...
        X