Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unwanted Double Execution

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

    Unwanted Double Execution

    Hello

    I'm running an automated strategy with no issues, except in a very specific situation:
    When my strategy generates a Long signal, a buy order is sent to the market to enter at 1 tick above the high of the current candle (let's say at a price of 1104). If the candle following the signal doesn't make this higher high, the order is cancelled. This part works well. Now, if a new Long signal is generated at a later stage in the same market, the process repeats itself. Let's say that in the meantime the market has fallen a bit and the new buy order is at 1101. This time, the tick higher is made and I'm now Long 1 contract. So far, so good.

    The problem is that once the entry price of the first (cancelled) order is reached (in this case 1104), a second Long order is triggered, which is clearly a mistake as this order was cancelled and is no longer valid.

    I'm posting the relevant code below and would very much appreciate any hints as to why this is happening.

    Thanks a lot.



    if(!orderPlacedLong && MyConditionsHere)

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


    else if (orderPlacedLong == true && High[0] <= High[1] && atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    {
    AtmStrategyCancelEntryOrder(orderId);
    orderPlacedLong = false;
    }


    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    {
    atmStrategyId = string.Empty;
    orderPlacedLong = false;
    }

    #2
    Hello laocoon,

    Thank you for your post.

    I do not see in the code you posted where a second order is not permitted at the first order's price level when the first order has been cancelled.

    If the order is cancelled then what prevents another order at that same level?

    I look forward to your response.
    Last edited by NinjaTrader_PatrickH; 07-02-2013, 06:47 AM.

    Comment


      #3
      Thanks for your post PatrickH.

      It is not that a second order is not permitted at the first order's price level (if the second order is by chance at the same level than the first that is perfectly OK), the problem is that once the first order has been cancelled (I can see it disappear from the DOM), it should obviously not be executed once the original entry price level is reached at a later stage. Right now the strategy is behaving as if the cancelled order was still active on the server of the exchange although it has been cancelled in my DOM.

      Thanks

      Comment


        #4
        Hello laocoon,

        Thank you for your response.

        So I may investigate this matter further please send me your log and trace files for today so that I may look into what occurred.

        You can do this by going to the Control Center-> Help-> Mail to Support.

        Please put 'ATTN: Patrick - 873471' in the subject line of your email and a reference to this thread in the body of the e-mail along with the time, price, and instrument for an instance of this scenario.

        I look forward to assisting you further.

        Comment


          #5
          it could have to do with cqg.
          They did have problems with orders not being cancelled. This happened last week and I got a notice that I had to reinstall Ninja Trader because of it.

          Could this be it ?

          Comment


            #6
            Hi shanemcdonald,

            Thanks for your post. I'm on Zen-Fire, but maybe they're having the same issue.

            Thanks

            Comment


              #7
              Hello laocoon,

              Thank you for your response.

              From your Log file I see the following.

              The R1 strategy submits the Entry for a price of 19.465 at 14:00:
              • 01.07.2013 14:00:00|1|32|Submitting order with strategy 'R1/fb88cd6ad36b4120ae25bfa320e77df6'
              • 01.07.2013 14:00:00|1|32|Order='21325971f6b142428f62e81ed5d38 ad5/Sim101' Name='Entry' New state=PendingSubmit Instrument='SI 09-13' Action=Buy Limit price=19.465 Stop price=19.465 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''

              This is then filled at 14:05:
              • 01.07.2013 14:05:01|1|32|Order='21325971f6b142428f62e81ed5d38 ad5/Sim101' Name='Entry' New state=Filled Instrument='SI 09-13' Action=Buy Limit price=19.465 Stop price=19.465 Quantity=1 Type=StopLimit Filled=1 Fill price=19.465 Error=NoError Native error=''

              However, the second entry you see for the SI is not from the R1 strategy. It is actually from the Robot1 strategy that submitted the order at 13:30:
              • 01.07.2013 13:30:05|1|32|Submitting order with strategy 'Robot1/e10a165fc0fa44869e11c6008adb1857'
              • 01.07.2013 13:30:05|1|32|Order='16806ccbd5ed43d99239c4bb3b46a df0/Sim101' Name='Entry' New state=PendingSubmit Instrument='SI 09-13' Action=Buy Limit price=19.49 Stop price=19.49 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''

              This is then filled at 14:09:
              • 01.07.2013 14:09:00|1|32|Order='16806ccbd5ed43d99239c4bb3b46a df0/Sim101' Name='Entry' New state=Filled Instrument='SI 09-13' Action=Buy Limit price=19.49 Stop price=19.49 Quantity=1 Type=StopLimit Filled=1 Fill price=19.49 Error=NoError Native error=''

              Please let me know if you have any questions.

              Comment


                #8
                Thanks for your detailed reply and your emails.
                You suggest using BarsSinceEntry to cancel my unfilled order, but I had a look at this method and I'm not sure how to use it in my case as an order shall only be cancelled if it hasn't been executed within one bar, ie there's no entry in the first place. What I want to achieve is this:

                An Long order is triggered by my strategy and sent to the market at bar n.
                If bar n+1 doesn't make a higher high than the high of n, the order shall be cancelled.
                If bar n+1 does make a higher high than the high of n, the order is executed and the ATM takes over until my Stop Profit is hit (this can take several bars).

                I did further testing and it appears indeed that the problem lies within the code I use for cancelling the order if it hasn't been filled after one bar. What's the best way to go about this, as I'm not sure how to use BarSinceEntry in this case? If I understand this command correctly, there must first be an entry to initiate the process, but in my case case there's none as I only want to cancel the order if it hasn't been filled.

                Thanks again.
                Last edited by laocoon; 07-02-2013, 01:24 AM.

                Comment


                  #9
                  Hello laocoon,

                  Thank you for your response.

                  If you want to ensure you are in a position before processing the cancellation then you can use MarketPosition: http://www.ninjatrader.com/support/h...etposition.htm

                  Please let me know if I may be of further assistance.

                  Comment


                    #10
                    Forex

                    Seems like this GetAtmStrategyUnrealizedProfitLoss(string AtmStrategyId) doesn't work on forex instruments. It keeps on getting log errors even do I have always check its ATM id before accessing it.

                    Comment


                      #11
                      Hello edward_bell,

                      Thank you for your post.

                      What do these errors report in the Log tab?

                      I look forward to your response.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by proptrade13, Today, 11:06 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by quantismo, 04-17-2024, 05:13 PM
                      4 responses
                      31 views
                      0 likes
                      Last Post quantismo  
                      Started by love2code2trade, 04-17-2024, 01:45 PM
                      4 responses
                      32 views
                      0 likes
                      Last Post love2code2trade  
                      Started by cls71, Today, 04:45 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post eDanny
                      by eDanny
                       
                      Started by kulwinder73, Today, 10:31 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Working...
                      X