Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to program two orders with different Stop loss and target ?

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

    How to program two orders with different Stop loss and target ?

    Hi everybody,

    I create a new topic to ask if someone have an exemple of code to have two orders running at the same time with different tp/sl. With the unmanaged approach, everything's great when running order one by one, but two at the same time isn't possible. I'm working since two weeks on this issue and it drives me crazy, and I don't understand what's wrong so if someone have already program this little piece of code...

    Thanks

    #2
    Hello After,

    Thank you for your post.

    I am not aware of such an example. I will put together and example and attach it to this post.

    I look forward to assisting you further.

    Comment


      #3
      Thanks Pat ! An exemple of this is all what I need

      Comment


        #4
        Hello After,

        Thank you for your patience.

        This example uses IOrder objects, but keep in mind I am not resetting the objects to null on fill and the OCO id is static.
        Code:
                #region Variables
        		private IOrder enter1;
        		private IOrder enter2;
        		private IOrder pt1;
        		private IOrder sl1;
        		private IOrder pt2;
        		private IOrder sl2;
                #endregion
        		
                protected override void Initialize()
                {
        			Unmanaged = true;
                }
        		
                protected override void OnBarUpdate()
                {	
        			if(Close[0] > Open[0]
        				&& Position.MarketPosition == MarketPosition.Flat)
        			{
        				// Two market orders
        				enter1 = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "enter1");
        				enter2 = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "enter2");
        			}
        			
        			// When we are long 2 suggesting the orders filled, place our protective orders.
        			if(Position.MarketPosition == MarketPosition.Long
        				&& Position.Quantity == 2)
        			{
        				// Profit Target and Stop Loss set 1
        				pt1 = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, enter1.AvgFillPrice+(5*TickSize), 0, "brckt1", "pt1");
        				sl1 = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, enter1.AvgFillPrice-(5*TickSize), 0 , "brckt1", "sl1");
        				
        				// Profit Target and Stop Loss set 2
        				pt2 = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, enter2.AvgFillPrice+(10*TickSize), 0, "brckt2", "pt2");
        				sl2 = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, enter2.AvgFillPrice-(10*TickSize), 0 , "brckt2", "sl2");
        			}
                }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        61 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        149 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X