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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X