Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with Two Consecutive Automated Orders

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

    Issue with Two Consecutive Automated Orders

    Hello

    I'm using an automated strategy on a 10 min chart. If the bar following the entry signal hasn't made a higher high (for Longs), the order is automatically cancelled after the bar has closed, ie an unfilled order can't be active for longer than 10 min. Now, if the next bar represents a valid entry signal again and the prior signal was cancelled, the strategy should trigger an automated order again, but as my code stands today it doesn't. The second order is simply ignored. I'm posting the code snippet below and would very much appreciate any input that solves this issue. Thanks in advance.

    if(!orderPlacedLong && my criteria here)

    {
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "MyStrat", "testStrategyIdValue");
    orderPlacedLong = true;
    }


    else if (orderPlacedLong == true && High[0] <= High[1])
    {
    AtmStrategyCancelEntryOrder(orderId);
    }

    #2
    laocoon, where do you reset orderPlacedLong then, so it would allow for new entries?

    As there's only two options why it would not place a new entry -

    a) an order is placed > so !orderPlacedLong rule not triggering
    b) your condition is not triggering, the second part of your if for entry
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Bertrand. I forgot to mention this part of my code:

      private bool orderPlacedShort = false;

      It can't be your suggested option b) because my conditions were definitely met, so it must be option a).
      What's strange though is that when there are two orders that aren't immediately following each other it works well, so I guess it's not a reset issue.
      Could it be a timing issue? What I mean by that is that after 10 min have passed, the order is cancelled if it wasn't executed and immediately afterwards the new order should be triggered if the conditions are met. All this happens in less than a second, so if the sequence of events is inversed or mixed up this could potentially cause the problem. Just guessing of course.

      Thanks

      Comment


        #4
        Thanks.

        'because my conditions were definitely met'

        How did you determine that to be 100%? Did confirm via prints?

        It could be a timing issue of the reset as well - if the OnBarUpdate() is condition is hit while your cancellation would still be processed and thus your bool not reset...you would only know for sure if the event sequence is analyzed via debug prints.

        Perhaps your code would also benefit from a rework of the logic, if you just canceled an order you wish to replace on the next bar - so the order can continue to work and you would have to deal with less cancellations and replacements.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Yes, via prints and via arrows that are drawn on the chart.
          The logic of the code isn't the problem here, it is only on very rare occasions that an order is immediately followed by another. What's more, the entry price of the order is always the high of the current candle +1 tick, so the order would have to be adapted anyway for the next candle as the entry price would be a different one.

          As you were suggesting, it is most likely a timing issue of the reset. Will have to look into this again.

          Thanks

          Comment


            #6
            Originally posted by laocoon View Post
            Hello

            I'm using an automated strategy on a 10 min chart. If the bar following the entry signal hasn't made a higher high (for Longs), the order is automatically cancelled after the bar has closed, ie an unfilled order can't be active for longer than 10 min. Now, if the next bar represents a valid entry signal again and the prior signal was cancelled, the strategy should trigger an automated order again, but as my code stands today it doesn't. The second order is simply ignored. I'm posting the code snippet below and would very much appreciate any input that solves this issue. Thanks in advance.

            if(!orderPlacedLong && my criteria here)

            {
            orderId = GetAtmStrategyUniqueId();
            AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "MyStrat", "testStrategyIdValue");
            orderPlacedLong = true;
            }


            else if (orderPlacedLong == true && High[0] <= High[1])
            {
            AtmStrategyCancelEntryOrder(orderId);
            }
            Unless you have reset orderPlacedLong somewhere that you are not showing, your order block will not be reentered.

            At the very least, you need to reset orderPlacedLong when you cancel your order.
            Code:
             ... else if (orderPlacedLong == true && High[0] <= High[1])
                        {
                            AtmStrategyCancelEntryOrder(orderId);
                            orderPlacedLong = false;
                        }
            Last edited by koganam; 04-17-2013, 08:52 AM.

            Comment


              #7
              Thanks a lot koganam.
              As so often in the past, you hit the nail on the head.

              Bertrand: you were of course right about the reset. As my strategy usually triggers about a signal per day per market, I didn't realise that it couldn't enter another one because I shut my system down every evening and so the next signal in the morning would be the first again.

              Thanks again to both of you.
              Last edited by laocoon; 04-17-2013, 08:08 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Touch-Ups, Today, 10:36 AM
              0 responses
              5 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
              24 views
              0 likes
              Last Post halgo_boulder  
              Working...
              X