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 algospoke, Yesterday, 06:40 PM
            2 responses
            19 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X