Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelling limit orders based off of time...

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

    Cancelling limit orders based off of time...

    Is there a stopwatch feature in Ninja Trader that allows me to cancel orders based off of time?

    Say I place a limit order... then after 10 seconds pass, I want to cancel the order.... so I can place it again anything of the such?

    #2
    BigDog008, please take a look at this sample for custom timer events used in NinjaScript - http://www.ninjatrader-support2.com/...ead.php?t=5965

    Comment


      #3
      could I use the ToTime() function?

      ie...

      some_variable = ToTime(Time[0])

      and then...

      if ToTime(Time[0]) > some_variable + 10

      CancelOrder()

      ??

      Comment


        #4
        This should also do it, or count the bars since order placement on a added tick or second timeframe.

        Comment


          #5
          Bertrand,

          I know this thread hasn't been updated in awhile but...

          How would you count the bars since order placement? and can this be done on a millisecond time frame?

          Comment


            #6
            For a basic start you can check into the snippet we have on the CancelOrder page - http://www.ninjatrader-support.com/H...ncelOrder.html

            This could of course also be done after the order reports for example filled (checking IOrder object fillstates).

            Comment


              #7
              the cancelorder page seems that will do it, However what would you suggest to replace barNumberOfOrder with that would put it in a Time parameter? Or could i use barNumberOfOrder and set that equal to something other than CurrentBar that would also put it into seconds or milliseconds.

              Comment


                #8
                wahooj,

                I am not exactly sure what you mean by 'barNumberOfOrder'. Can you please clarify?
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  barNumberofOrder is used as a variable in the help file.
                  http://www.ninjatrader-support2.com/...ead.php?t=5965

                  In the cancel example, barNumberofOrder variable is set = 0, and then set as Currentbar which is an int. What variable type would I create if I later want to set it to a time format (seconds or millisecs).
                  So, if I used the cancel example:

                  private IOrder myEntryOrder = null;
                  private ?? variable = 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");
                  variable = _Some Time Format_;

                  // If more than 5 bars has elapsed, cancel the entry order
                  if (_Some Time Format_ > variable + 5)
                  CancelOrder(myEntryOrder);
                  }

                  hope i made sense...

                  Comment


                    #10
                    Hello,

                    I will have someone reply to you on Monday. Thank you for your patience.
                    DenNinjaTrader Customer Service

                    Comment


                      #11
                      wahooj, either you work directly with a DateTime in C# or you convert to an Int for easier handling via the ToTime() method -

                      Comment


                        #12
                        Would it be something similar to how BigDog008 did it below, because i tried that in market replay mode and realtime simulator with no luck. I don't think I had log errors but I'll try it again. thanks

                        Comment


                          #13
                          wahooj, yes in general that approach should work - you would need to ensure the timeframe you're working on offers enough granularity in timestamps for your rules to trigger. For this it would be best work with Print statements throughout code and our TraceOrders feature to debug.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          628 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          359 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          105 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          562 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          568 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X