Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Triangle Break out: Internal Order Handling rules issue

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

    Triangle Break out: Internal Order Handling rules issue

    I have a strategy that watches for triangles, and looks to enter on a break out in either direction via stop limit orders. I know that you can not have EnterShortStopLimit and EnterLongStopLimit active at the same time, so the strategy monitors price, and puts in place long orders when near the top of the triangle and short orders when near the bottom.

    I'm running into an issue where I have a EnterLongStopLimit active, price then moves toward the bottom of the triangle, but the EnterShortStopLimit is ignored. I have TraceOrders set to true, and in the log I get the following message:

    "An Enter() method to submit an entry order at '10/25/2011 10:50:43 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

    Here is the code that handles the orders:

    if (longSetup && shortSetup && Position.MarketPosition == MarketPosition.Flat)
    {
    //monitor price action and submit an entry order for which ever one is closest
    if (Close[0] - shortEntry > longEntry - Close[0])
    {
    if (shortEntryOrder != null)
    CancelOrder(shortEntryOrder);
    if (shortStopOrder != null)
    CancelOrder(shortStopOrder);
    if (shortTargetOrder != null)
    CancelOrder(shortTargetOrder);

    longEntryOrder = EnterLongStopLimit(longEntry, longEntry, "long_entry");
    longStopOrder = ExitLongStop(longStop, "long_entry");
    longTargetOrder = ExitLongLimit(longPT, "long_entry");

    shortOnReversal = true;
    }
    else
    {
    if (longEntryOrder != null)
    CancelOrder(longEntryOrder);
    if (longStopOrder != null)
    CancelOrder(longStopOrder);
    if (longTargetOrder != null)
    CancelOrder(longTargetOrder);

    shortEntryOrder = EnterShortStopLimit(shortEntry, shortEntry, "short_entry");
    shortStopOrder = ExitShortStop(shortStop, "short_entry");
    shortTargetOrder = ExitShortLimit(shortPT, "short_entry");

    longOnReversal = true;
    }
    }
    What am I doing wrong? What is the best way to handle this scenario?

    Thanks!

    #2
    Hello Style, I would not 'lump' both sides together as you do here -

    ... longSetup && shortSetup ....

    as you would run into race conditions doing so, treat each side needed independently and ensure waiting for a order cancellelation confirmation before attempting to place the new entry.

    Comment


      #3
      What do you mean handle them independently? If I only have a short setup, then I don’t need to worry about canceling orders, I simply run EnterShortStopLimit. If I only have a long setup, then I don’t need to worry about canceling orders, I simply run EnterLongStopLimit. Those scenarios I do handle independently, but that is not where I’m having issues with orders being ignored.

      It is only when I have both a short and a long setup that I need to monitor the price action to see if it is closer to the top of the triangle or the bottom. The way I know when I have both is via the longSetup && shortSetup logic.

      If you look closely, after I check for longSetup && shortSetup I then do the following:

      if (Close[0] - shortEntry > longEntry - Close[0])
      // then handle a long entry as price action is closer to the top of the triangle.
      else
      // handle a short entry

      In that manner I do handle the independently. I’ve attached my code so you can see what I mean.

      as you would run into race conditions doing so, treat each side needed independently and ensure waiting for a order cancellelation confirmation before attempting to place the new entry.
      I think this is the piece I need to fix the issue. How best do you monitor for order cancellation?

      I have CalculateOnBarClose = true. Shouldn’t the entry orders expire at the close of each bar anyway?
      Attached Files
      Last edited by Style; 03-28-2012, 09:01 AM.

      Comment


        #4
        Thanks for the clarification Style - so could there be a scenario where your code is really attempting to place 2 opposing orders in the managed approach? This would not be possible, as it would be getting caught by the order handling rules as you've seen.

        To properly wait for the orderstate change to .Cancelled you would monitor the IOrder object in OnOrderUpdate() and nullify it as needed.

        Comment


          #5
          OK, I've made the change to listen for the order to be canceled via OnOrderUpdate, and I no longer get the "order has been ignored" message. However, since the order is not executing on a break out of the triangle, it's clear that the order isn't being submitted period.

          Here is the code:

          if (longSetup && shortSetup && Position.MarketPosition == MarketPosition.Flat)
          {
          //monitor price action and submit an entry order for which ever one is closest
          if (Close[0] - shortEntry > longEntry - Close[0])
          {
          if (shortEntryOrder != null) // Cancel the short orders and submit the long orders via OnOrderUpdate
          {
          longOnCancel = true;

          CancelOrder(shortEntryOrder);

          if (shortStopOrder != null)
          CancelOrder(shortStopOrder);
          if (shortTargetOrder != null)
          CancelOrder(shortTargetOrder);
          }
          else // submit the orders here
          {
          longEntryOrder = EnterLongStopLimit(longEntry, longEntry, "long_entry");
          longStopOrder = ExitLongStop(longStop, "long_entry");
          longTargetOrder = ExitLongLimit(longPT, "long_entry");
          }

          shortOnReversal = true;
          }
          else
          {
          if (longEntryOrder != null)
          {
          shortOnCancel = true;

          CancelOrder(longEntryOrder);

          if (longStopOrder != null)
          CancelOrder(longStopOrder);
          if (longTargetOrder != null)
          CancelOrder(longTargetOrder);
          }
          else
          {
          shortEntryOrder = EnterShortStopLimit(shortEntry, shortEntry, "short_entry");
          shortStopOrder = ExitShortStop(shortStop, "short_entry");
          shortTargetOrder = ExitShortLimit(shortPT, "short_entry");
          }

          longOnReversal = true;
          }
          }
          protected override void OnOrderUpdate(IOrder order)
          {
          // Listen for canceled entry orders where we're to submit entry orders in the other direction
          if (longEntryOrder != null && longEntryOrder == order && shortOnCancel
          && order.OrderState == OrderState.Cancelled && order.Filled == 0)

          {
          shortEntryOrder = EnterShortStopLimit(shortEntry, shortEntry, "short_entry");
          shortStopOrder = ExitShortStop(shortStop, "short_entry");
          shortTargetOrder = ExitShortLimit(shortPT, "short_entry");
          }

          if (shortEntryOrder != null && shortEntryOrder == order && longOnCancel
          && order.OrderState == OrderState.Cancelled && order.Filled == 0)
          {
          longEntryOrder = EnterLongStopLimit(longEntry, longEntry, "long_entry");
          longStopOrder = ExitLongStop(longStop, "long_entry");
          longTargetOrder = ExitLongLimit(longPT, "long_entry");
          }
          }
          Does bold and underlined section above look right? It doesn't appear that it's getting to the part that fires off the short entry order. Please advise.

          Thanks!
          Attached Files
          Last edited by Style; 03-28-2012, 03:23 PM.

          Comment


            #6
            I've found a fix. If I use CancelAllOrders(true, true) instead of CancelOrder(longEntryOrder) I don't even need to use OnOrderUpdate to monitor for the cancellation of the order. The following code works just fine without any OnOrderUpdate function:

            if (Close[0] - shortEntry > longEntry - Close[0])
            {
            CancelAllOrders(true, true);

            longEntryOrder = EnterLongStopLimit(longEntry, longEntry, "long_entry");
            longStopOrder = ExitLongStop(longStop, "long_entry");
            longTargetOrder = ExitLongLimit(longPT, "long_entry");

            shortOnReversal = true;
            }
            else
            {
            CancelAllOrders(true, true);

            shortEntryOrder = EnterShortStopLimit(shortEntry, shortEntry, "short_entry");
            shortStopOrder = ExitShortStop(shortStop, "short_entry");
            shortTargetOrder = ExitShortLimit(shortPT, "short_entry");

            longOnReversal = true;
            }
            Thanks for your help Bertrand.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            656 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            371 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            579 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X