Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error creating new order-Internal Order Handling Rules that Reduce Unwanted Positions

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

    Error creating new order-Internal Order Handling Rules that Reduce Unwanted Positions

    I have a strategy that's trading stocks, and due to brokerage regulations I cannot make large short orders. It was suggested to me by IBKR support to make a number of short orders within regulation. I wrote this code to perform this action. The intention is to wait for the reversal order to fill, and immediately once it fills, generate a new order. Repeat until the size target is reached. My issue is that sometimes it will trigger and error:

    2024-05-17 11:39:14:856|3|4|Strategy 'UpdateOrderTest/319956703': An Enter() method to submit an entry order at '05/17/2024 11:39:11' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.

    I looked up the rules and didn't see what I was breaking. Could I get some advice on what's going wrong here? The code is below.

    Code:
            #region OnOrderUpdate - Additional short entries
            protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                                        int quantity, int filled, double averageFillPrice,
                                        Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
            {
                //ensure the correct instrument and order name
                if (order.Instrument == Instrument && orderState == OrderState.Filled &&
                    (order.Name == "VWMA Reversal" || order.Name == "VWMA Reversal Continuation")){    
                        orderSize = (int)((accountSize / (25)) / Closes[1][0]);
                        if (Position.Quantity < orderSize * EntriesPerDirection){
                            EnterShortLimit(0,false,orderSize,GetCurrentBid()*.99,"VWMA Reversal Continuation");
                            Print(Instrument + " new Reversal Cont = " + GetCurrentBid()*.99);
                    }
                }
            }
            #endregion​

    #2
    Hello RaddiFX,

    The warning points to the help guide page because you would need to look at what orders you have going on at that time to address the question. The rules that you are hitting would be one of the following:

    Methods that generate orders to enter a position will be ignored if:
    •A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
    •A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
    •A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored.
    •The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
    •The entry signal name is not unique


    From the code provided the only item I can see is that you are using a non unique signal name, if you wanted to place more than 1 entry as limit orders you need to have a different signal name for the second entry.

    Comment


      #3
      Gotcha. I won't have time to implement this before the market closes for the day, but could you confirm if a change like this would work? The changes are checking to see if the order name contains "vwma reversal", and adding a unique number to the end of the new order name.

      Code:
              #region OnOrderUpdate - Additional short entries
              protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                                          int quantity, int filled, double averageFillPrice,
                                          Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
              {
                  //ensure the correct instrument and order name
                  if (order.Instrument == Instrument && orderState == OrderState.Filled &&
                      order.Name.ToLower().Contains("vwma reversal"))
                  {    
                      orderSize = (int)((accountSize / (25)) / Closes[1][0]);
                      if (Position.Quantity < orderSize * EntriesPerDirection){
                          long randomFiveDigitNumber = long.Parse(new Random().Next(1, 10) + new string(Enumerable.Range(0, 4).Select(_ => new Random().Next(0, 10).ToString()[0]).ToArray()));
                          EnterShortLimit(0,false,orderSize,GetCurrentBid()*.99,("VWMA Reversal Continuation - " + DateTime.UtcNow.ToString() + randomFiveDigitNumber.ToString()));
                      }
                  }
              }
              #endregion​​
      Adding the unix timestamp Plus a random 5 digit number to the end should (almost)always return unique.

      Comment


        #4
        Hello RaddiFX,

        You will need to try that and see if that was the issue. If you want to test it after the market closes you can test it on the playback connection.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        46 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        66 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X