Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() problem

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

    #31
    I don't have a problem with the script trying to submit additional orders when one is already in play.... I just don't want it to cancel the limit order at the begining of the next bar if its not executed...

    Comment


      #32
      John833,

      When you resubmit an order that gets ignored you have essentially messed up the IOrder object associated with it. You will need to limit your condition to submit only one order at a time. Add yourself a bool flag.

      Add this into your conditions:
      Code:
      if (inTrade == false)
      {
           myEntryOrder = EnterLongLimit(...);
           inTrade = true;
           barNumberOfOrder = CurrentBar;
      }
      
      if (CurrentBar > barNumberOfOrder + 3 && myEntryOrder != null)
      {
           CancelOrder(myEntryOrder);
           inTrade = false;
      }
      Josh P.NinjaTrader Customer Service

      Comment


        #33
        oh I see.... I'll give this a go... thanks Josh

        Comment


          #34
          Josh
          I’ve added the conditions in, and a CS0103 “the name’inTrade’ does not exist in the current context” error has come up.
          So I have added in the Variable region under private IOrder myEntryOrder = null;
          private bool intrade = false;

          but the same error has come up…. have I put the new variable in the wrong location in the code?
          Thanks….
          Last edited by John833; 10-31-2008, 09:46 AM.

          Comment


            #35
            You need to use the same capitalization when you declare the variable.
            Code:
            private bool in[B][COLOR=Red]T[/COLOR][/B]rade = false;
            Josh P.NinjaTrader Customer Service

            Comment


              #36
              Wow….. I think it works…..!!!!!
              Thanks again Josh…very much appreciated!

              Comment


                #37
                Josh, this is very strange…. The strategy worked cancelling unexecuted limit orders on the required bar… I then changed one of the parameters
                barNumberOfOrder + 3 to
                barNumberOfOrder + 5
                The strategy then started to cancel unexecuted limit orders on the next bar again. I changed back the value back to +3, which had no affect. I then rewrote the whole strategy and recompiled it…. Again no effect, the strategy now bizzarely cancels unexecuted limit orders at the start of the next bar. Back to square one….
                Is there something that needs to be reset in the code? I have also tried closing NT down and reopening it with no effect…
                Do you have any idea what might be going on? This doesn't seem to make sense....
                Last edited by John833; 10-31-2008, 11:39 AM.

                Comment


                  #38
                  John833,

                  I don't know what you have changed exactly. Re-import the working version and start again. If you only changed a 3 to a 5 it should not matter, but if you are experiencing completely different behavior you need to debug it step by step. When something is not working you need to rewind and then sequentially proceed forward. Use print functions everywhere to figure out what your code is doing. Start with the base case that you know was working and then make changes till it breaks again. Then you will know what is causing the problem and how to fix it. Also, always check the Control Center logs for errors. Please review this tip: http://www.ninjatrader-support.com/v...ead.php?t=3418
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #39
                    Thanks again Josh

                    Comment


                      #40
                      Hi Josh, I have rewritten the code and compiled it several times, unfortunately I still am getting the same results of unexecuted limit orders cancelling in the following bar. I have added print statements but I'm really out of my depth here.
                      I’m almost sure the script worked a couple of times, I would be really grateful if you could have a quick look…. Have I added something not compatible with Ninja Script? At the moment I am completely at a loss…
                      Any help would be much appreciated….
                      Regards John

                      (by the way there are no errors on the Control Centre log)
                      Attached Files
                      Last edited by John833; 10-31-2008, 02:10 PM.

                      Comment


                        #41
                        John,

                        In your code you have forgotten the liveUntilCancelled part we discussed earlier.

                        This is your current line:
                        Code:
                        myEntryOrder = EnterShortLimit(1, DonchianChannel(Dperiod).Lower[1], "Dn");
                        Without setting liveUntilCancelled = true your order will automatically be cancelled on the next bar as it is not resubmitted.

                        EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

                        Code:
                        myEntryOrder = EnterShortLimit(0, true, 1, DonchianChannel(Dperiod).Lower[1], "Dn");
                        The same applies for longs.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #42
                          Thanks again Josh

                          That was a hard lesson for me to learn, I must have inadvertantly deleted the script I was working on when I was cleaning up my files... and I've been trying to dig myself out of this mess for the last 3 hours!!!!

                          I'm sure I won't do that again....lol

                          Regards

                          John

                          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