Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Instrument Combined Exit

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

    Multi Instrument Combined Exit

    I have similar code working in a single instrument strategy but cannot get it working in my multi instrument strategy. I have 2 instrument dataseries that I have entry orders on and a 3rd (1 range) data series for one of the instruments to look for a combined exit.

    Code:
    if(BarsInProgress == 2);
    		{
    			if(Position.MarketPosition != MarketPosition.Flat)
    			{
    				if(Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) >= TopProfit 
    					|| Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) <= -TopStop)
    					
    					{
    					ExitLong(0, Positions[0].Quantity, "Es Combined", "EsLE");
    					ExitShort(0, Positions[0].Quantity, "Es Combined", "EsSE");
    					
    					ExitLong(1, Positions[1].Quantity, " Zn Combined", "ZnLE");	
    					ExitShort(1, Positions[1].Quantity, "Zn Combined", "ZnSE");
    					}
    			}
    		}
    Two questions:

    1) How do I get this working with multiple instruments?

    2) Would it be better to do this check in BarsInProgress 1 and 2 instead? I thought about this but wondered if it my send double the exit orders if they both triggered at the same time leading to unwanted positions.

    #2
    Hello CableTrader007,

    What is BarsInProgress == 2? Is this a range of either ES or ZN?

    I ask because you have Position.MarketPosition check which only apply to the BarsInProgress that it's nested in, in this case BIP 2
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Yes, that is correct. BarsInProgress == 2 is a 1 range series of ES. My other series are longer times so I am trying to look at this.

      Would it be better to use this code in a separate series 2 (1 range ES) and 3 (1 range ZN) with the exit orders for that particular instrument only in each section of code?

      Code:
      if(BarsInProgress == 2); // 1 range ES
      		{
      			if(Position.MarketPosition != MarketPosition.Flat)
      			{
      				if(Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) >= TopProfit 
      					|| Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) <= -TopStop)
      					
      					{
      					ExitLong(2, Positions[2].Quantity, "Es Combined", "EsLE");
      					ExitShort(2, Positions[2].Quantity, "Es Combined", "EsSE");
      					}
      			}
      		}
      
      if(BarsInProgress == 3); // 1 range ZN
      		{
      			if(Position.MarketPosition != MarketPosition.Flat)
      			{
      				if(Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) >= TopProfit 
      					|| Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) <= -TopStop)
      					
      					{
      					ExitLong(3, Positions[3].Quantity, "Zn Combined", "ZnLE");
      					ExitShort(3, Positions[3].Quantity, "Zn Combined", "ZnSE");
      					}
      			}
      		}
      Would I have to submit the orders in the 1 range dataseries originally for this check to work? Thank you.

      Comment


        #4
        CableTrader007,

        That would be good to ensure that only the data is being received by the script for the instrument you want to submit the order to.

        Have you tested this script on your side?
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X