Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correct syntax for Managed oco orders

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

    Correct syntax for Managed oco orders

    Hello,

    I have a managed strategy that moves a stop (I think I understand the naming part but want to ensure proper cancelling of oco orders). So far these are the various states of the stop orders. The initial placement, the breakeven position, the initial trail stop location, then the trailing locations. Some of these are set in OnExecution, some in OnOrder or OnBarUpdate...

    Code:
    stopOrder_1a = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 14 * TickSize, "stopa", "a long limit entry");
    stopOrder_1a = ExitLongStop(0, true, stopOrder_1a.Quantity, Position.AvgPrice+1*TickSize, "b/e-stopa", "a long limit entry");
    stopOrder_1a = ExitLongStop(0, true, stopOrder_1a.Quantity, adjustedStopPrice, "init trail stopa", "a long limit entry");
    stopOrder_1a = ExitLongStop(0, true, stopOrder_1a.Quantity, adjustedStopPrice, "trail stopa", "a long limit entry");
    Because I was thinking I need to cancel or nullify the order prior to placing the newest order, I was trying the following without success...

    Code:
    for example...
    if (stopOrder_1a.Name == "init trail stopa") stopOrder_1a = null;/*CancelOrder(stopOrder_1a);*/
    Possibly, I'm not understanding the right section to place these cancel orders in...
    Any help you can offer is appreciated.
    Kirk
    Last edited by zeller4; 01-19-2012, 07:32 PM.

    #2
    Kirk, for providing the OCO part it would be best to work in OnExecution() checking the fillstates of the exit orders, if one leg reports filled you would then need to CancelOrder() the other one, then once the Cancel is processed and you get the state confirmed in OnOrderUpdate() you can nullify them.

    Comment


      #3
      Bertrand,

      Thanks but I'm still working through this with no success yet.

      I have determined that in OnExecution section, I can check this for an "accepted" orderstate but it never gets "filled" (unless I don't understand how "filled" works- I'm assuming filled is if the stop actually gets hit...):

      Code:
      //(this is in OnExecution)...
      if (stopOrder_1a != null && stopOrder_1a == execution.Order)
      {
      if (execution.Order.OrderState == OrderState.Accepted)
      	{
      		if (stopOrder_1a.Name == "stopa") stopOrder_1a = null;	
      	}
      }
      When the stop order is in the accepted state and another new stop with a different name ( i.e. "b/e-stopa") is added, I need to cancel the previous order ("stopa").

      Do you have a suggestion for the code I need to add in OnOrderUpdate (or OnBarUpdate or OnExecution)?
      I appreciate your help.
      Kirk
      Last edited by zeller4; 01-24-2012, 08:36 PM.

      Comment


        #4
        Hi Kirk, I'm not exactly sure what you're trying to achieve here with the OCO'ing of your stops - are you trying to update a resting stop order to a new price?

        Comment


          #5
          yes, but using a new name for the order - couldn't find a trailing stop sample anywhere...

          I'm trying to name the stop order "stopa", "b/e-stopa", "trailing stopa"...


          If I stay with only the name "stopa" each time the stop is updated, I don't need to cancel that when the stopprice is updated, correct?

          Comment


            #6
            Correct, if I were you I would only update the stop as needed to provide the trailing aspect - here's the basic concept using an initial stop and updating as needed, it uses the Set() methods but you can use the same approach using the Exit() methods, a resubmission using the same name would cause an automatic update of the order.

            Comment


              #7
              Would be nice if someone would update the samples...

              If I understand use of managed orders and IOrder, you don't use Set()...

              So, if I'm going to modify your sample for my own use, which section does this go in?

              Code:
              //Sample shows this in OnBarUpdate...
              // Resets the stop loss to the original value when all positions are closed
              			if (Position.MarketPosition == MarketPosition.Flat)
              			{
              				SetStopLoss(CalculationMode.Ticks, stoplossticks);
              			}
              			
              			// If a long position is open, allow for stop loss modification to breakeven
              			else if (Position.MarketPosition == MarketPosition.Long)
              			{
              				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
              				if (Close[0] > Position.AvgPrice + 5 * TickSize)
              				{
              					SetStopLoss(CalculationMode.Price, Position.AvgPrice);
              					
              				}
              			}
              Last edited by zeller4; 01-25-2012, 10:06 AM.

              Comment


                #8
                Originally posted by zeller4 View Post
                If I understand use of managed orders and IOrder, you don't use Set()...
                That's not correct - you can use either Set() or Exit() methods. Set() methods would not offer any IOrder returns and thus using IOrders with the Exit() methods would be the more advanced managed approach if you will. But the order handling rules and signal tracking under the hood would still be active, thus still managed mode.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                671 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                379 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                111 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                582 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X