Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() problem

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

    #16
    Josh, I have just added
    Print(BarsSinceEntry().ToString();
    I think I can see what the problem is, my data series uses 1 minute time frames, and this is what I get….
    I can understand that the order is cancelled because BarsSinceEntry is more than 3.
    Looking back at the output it would appear that BarsSinceEntry only resets to 0 when a limit order is executed.
    So is there a way that BarsSinceEntry can be reset to 0 when a limit order is placed but not executed? Or is there a way round this?
    11
    12
    13
    14
    15
    10:22AM Entered internal PlaceOrder() method at 10:22:00AM: Action=SellShort OrderType=Limit Quantity =1…..etc
    Cancelled custom managed order at 10:23:00 AM: Order='NT-00002/Back101'....etc
    16
    17
    18
    Last edited by John833; 10-30-2008, 02:27 PM.

    Comment


      #17
      I see what you are saying John. You may need to revert back to your original idea of manually tracking it in that instance. You could give this a last try though:

      BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)
      Code:
      Print(BarsSinceEntry(0, "", 0).ToString());
      If that does not work then you will need to use your own tracker.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Thanks for your help Josh, I think you’re right I need to track this manually. What is confusing is that there is sample code of exactly what I am trying to achieve in your online manual under CancelOrder().
        I originally got the code from there and I have been struggling with it for the last couple of days, no matter how I write the code it doesn’t seem to work… can you see if there is an error in it?


        From NT V6 Help Guide


        CancelOrder()

        private IOrder myEntryOrder = null;
        private int barNumberOfOrder = 0;

        protected override void OnBarUpdate()
        {
        // Submit an entry order at the low of a bar
        if (myEntryOrder == null)
        {
        myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
        barNumberOfOrder = CurrentBar;
        }

        // If more than 5 bars has elapsed, cancel the entry order
        if (CurrentBar > barNumberOfOrder + 5)
        CancelOrder(myEntryOrder);
        }
        Last edited by John833; 10-30-2008, 02:57 PM.

        Comment


          #19
          Hi John,

          If you don't mind, why don't you upload the NinjaScript Strategy you have at this point in time? This way we can be on exactly the same page. Thanks.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            ok, how do I do that?

            Comment


              #21
              File->Utilities->Export NinjaScript.
              Then in your next post press the "Manage Attachments" button to add the .zip file to here. Thanks.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                Hi Josh
                This is the strategy which I have tried to incorporate the sample code from your online manual under CancelOrder(). It seems to cancel limit orders almost straight away…
                Thanks for your help….
                Attached Files
                Last edited by John833; 10-30-2008, 04:36 PM.

                Comment


                  #23
                  Hi John,

                  Okay. Here is the problem. When you are using if (CurrentBar > ...) the condition evaluates to true before you have even placed a trade.

                  When you never trade yet your barNumberOfOrder is 0. The moment CurrentBar is greater than 3 it will call your CancelOrder(). Issue here is that the IOrder object is still null because no entry order has ever been made yet. So to fix this you will need to add an additional check of myEntryOrder != null. Please see the reattached strategy and comments inside.

                  Please be aware that even though I fixed the CancelOrder issue, you still have a problem with your code that you need to address. You cannot have two Enter limit orders working in opposite directions at the same time. Please refer to the bottom of this article: http://www.ninjatrader-support.com/H...verview36.html
                  Attached Files
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Josh, your knowledge of NT is outstanding and the support you have provided has been quite remarkable.
                    Thanks again for your patience and help
                    Regards
                    John

                    Comment


                      #25
                      Hi Josh, I tried out the amended strategy using live data on a sim account, and unfortunately I have discovered that submitted limit orders that are not exectuted are still being cancelled at the beginning of the next bar.
                      This is the output that I’m seeing….

                      4:09:39 PM Entered internal Place Order() method at 10/31/2008 4:09:39 PM: Action=Buy OrderType=LimitQuantity=1 LimitPrice=13480…….etc

                      These next 2 lines are repeated several times a every second….
                      4:09:40 PM Entered internal Place Order() method at 10/31/2008 4:09:40 PM: Action=BuyOrderType= LimitQuantity=1 LimitPrice=13480……etc
                      4:09:40 PM Ignored PlaceOrder() method: Action=BuyOrderType=Limit Quantity=1 LimitPrice=13840 StopPrice=0 SignalName=Up’FromEntrySignal=”Reason=’There already is a matching order with the same prices and quantity’

                      until
                      4:10:00 PM Cancelled expired order. BarsInProgress=0: Order=’………….etc

                      Its very strange as I thought your amended script worked ok yesterday, but when I backtest your script today again it appears that it also cancels orders in the next bar.
                      Could you have a look at the script you sent me, and are you seeing the same thing as me?

                      Thanks again...
                      Last edited by John833; 10-31-2008, 04:07 AM.

                      Comment


                        #26
                        What instrument and time frame are you backtesting on? What kind of chart? 1min? Daily?
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi Josh, I’m testing on Hang Seng Futures with a 1min time frame… you can also try it on ES Dec with a stop at 8 and a profit target at 25.
                          Last edited by John833; 10-31-2008, 08:35 AM.

                          Comment


                            #28
                            Unfortunately I do not see this issue on my end. Generally that error is not a problem though. It comes up when you already have an order in play and you submit another order with exactly the same information. In that case it will just ignore it because you are using liveUntilCancelled = true and the order does not need resubmissions to stay alive. You could program your own logic to not submit orders while you have one in play or you can just let NT ignore it internally.

                            In your case I suggest you program something that limits it from trading because if your logic goes back into the submission loop it is going to mess with your barNumberOfOrder variable.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #29
                              Hi Josh, are you saying that when you run the strategy, submitted limit orders that are not exectuted are NOT being cancelled at the beginning of the next bar, and are live until the 3rd bar?
                              Is that right?

                              Comment


                                #30
                                What I'm hoping the strategy to achieve is to submit a limit order, which will be cancelled by the 3rd bar if it is not executed...

                                I thought that was what your amendment on the strategy yesterday was going to do?
                                Last edited by John833; 10-31-2008, 08:50 AM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                580 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                335 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                102 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                554 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                552 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X