Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO question

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

    OCO question

    I'm using Unmanaged orders and using the OCO param. I enter entry, stop exit & limit exit orders for 2 lots. When just 1 lot gets filled at my (limit) target the stop for both lots gets cancelled. Is this expected behavior?

    Thanks,

    Paul

    #2
    Hello Paul,

    Thank you for your post.

    This is not expected behavior. Please respond with the code/syntax used for your Entry, Limit and Stop.

    I look forward to your response.

    Comment


      #3
      I'll list just the long side for simplicity:

      In OnBarUpdate:

      private void IssueLongOrder(double dEntryLong)
      {
      // Make a unique order name
      iTradeNumberLong++;
      sLongTradeLabel = sLongTradeLabelBase + iTradeNumberLong.ToString();

      liLog.LogMsg("Long Entry1 SubmitOrder " + dEntryLong.ToString() + "," + sLongTradeLabel);
      ioEntryOrderLong = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, iContracts, 0, dEntryLong, "EntryOCO", sLongTradeLabel);
      // rejected orders will cause us to stop trading.
      if (ioEntryOrderLong == null)
      {
      liLog.LogMsg("NULL IOrder returned from Long SubmitOrder()");
      throw new Exception("NULL IOrder returned from Long SubmitOrder()");
      }
      else if (ioEntryOrderLong.OrderState == OrderState.Rejected)
      {
      liLog.LogMsg("Long Entry Order Rejected, OrderID = " + ioEntryOrderLong.ToString());
      throw new Exception("Long Entry Order Rejected, OrderID = " + ioEntryOrderLong.ToString());
      }
      }

      And In OnExecution:

      if (execution.Name == sLongTradeLabel &&
      execution.Order.OrderAction == OrderAction.Buy) // Normal Entry
      {
      liLog.LogMsg("OnExecution() SIGLONG, entered position at " + execution.Price.ToString() + "," + sLongTradeLabel);

      iTrades++;

      if (bUseExecutionPrice == true)
      dEntryPriceLong = execution.Price;

      // set targets
      dTargetPriceLong1 = dEntryPriceLong + iTicksFirstTarget * TickSize; //Initial fixed Target
      dTargetPriceLong2 = dEntryPriceLong + iTicksSecondTarget * TickSize; //Initial fixed Target
      liLog.LogMsg("Long Target1 SubmitOrder(dTarget1PriceLong) " + dTargetPriceLong1.ToString());
      ioEntryOrder1LongLimit = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, iContracts/2, dTargetPriceLong1, 0, "TgtAndStpOCO", sLongTradeLabel);
      liLog.LogMsg("Long Target2 SubmitOrder(dTarget2PriceLong) " + dTargetPriceLong2.ToString());
      ioEntryOrder2LongLimit = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, iContracts/2, dTargetPriceLong2, 0, "TgtAndStpOCO", sLongTradeLabel);

      // set stops
      dStopPriceLong = dEntryPriceLong - iTicksInitialStop * TickSize; //Initial Stop
      liLog.LogMsg("Long Stop SubmitOrder(dStopPriceLong) " + dStopPriceLong.ToString());
      ioEntryOrderLongStop = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, iContracts, 0, dStopPriceLong, "TgtAndStpOCO", sLongTradeLabel);
      theState = State.ST_INLONG;
      }

      Thanks Patrick, if you want all the code then let me have an email address because there is also a short side entry & stops & targets.

      Comment


        #4
        Hello Paul,

        Thank you for your response.

        You have two Limits associated to one Stop, when one limit is filled the Stop will be cancelled as well as the other Limit.

        Set two Stops as you have with the two Limits, and set one Stop to the same ocoid as one Limit, then repeat for the next Stop and Limit but use a different ocoid.

        Please let me know if you have any questions.

        Comment


          #5
          Thanks Patrick,

          that was the basis of my original question - that if one target gets filled would it be expected that the stop for both lots would be cancelled. I can certainly code to use 2 different ocoid's. That does bring up another question though:

          If I were to enter 2 lots with the same stop & limit exit prices & the same ocoid's but only one exit limit was filled (due to market action), would the stop on both lots still get cancelled. A theoretical question since that's not what I'm doing but it would be nice to know....

          Thanks for your time,

          Paul

          Comment


            #6
            Hello Paul,

            Thank you for your response.

            That is correct, if one order is filled then the other orders with the same ocoid will be cancelled.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            2 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            8 responses
            61 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            4 responses
            3,289 views
            1 like
            Last Post jgualdronc  
            Started by Option Whisperer, Today, 09:55 AM
            0 responses
            5 views
            0 likes
            Last Post Option Whisperer  
            Started by halgo_boulder, 04-20-2024, 08:44 AM
            2 responses
            22 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X