Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Keep Limit Order Alive for 3 Minutes

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

    Keep Limit Order Alive for 3 Minutes

    I have a simple problem, but I could not find it in the forum, only things I found were "timespan" and "this is C# go and look there".

    Please provide code to cancel a limit entry order simply 3 minutes after it was initiated, e.g. order sent out at 9:45:33 so it should expire (being cancelled) at 9:48:33. [ OnBarClose = false ].

    The issues I am having are:
    a) How to simply get the current time in a format to be compared, and how to compare it (if timeNow >= timeStart + 3 minutes).
    b) What to use in the OnBarUpdate() loop (where I guess the time comparing should be placed) to see that this order is still pending.

    Thank you!

    #2
    Hi BillCh, you could set the parameter liveUntilCancelled to true when placing the limit order -

    Code:
    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice,string signalName)
    For time comparisons you can use ToTime - http://www.ninjatrader-support.com/H...V6/ToTime.html

    To check the orderstate, you want to move to the OnExecution() - http://www.ninjatrader-support.com/H...Execution.html

    To see an overview over the different orderstates in the IOrder object, please check this link - http://www.ninjatrader-support.com/H...V6/IOrder.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      a. ToTime(Time[0]) will give you the time of the current bar as an integer in HHMMSS format. To add 3 minutes to it just add 300 to the integer.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Thank you for your answers.

        I am trying to work with liveUntilCancelled and I am executing per tick, so I could use ToTime(DateTime.Now) but if I would enter at 9:59:20 I get 95920 and adding 300 would result in 96220 (or 9:62:20) which does not exist and if I would compare the integer to the entry integer value +3 mimutes (+300) or substract it from the actual time it would not work.

        I tried to solve this with:
        nowCalcTime = DateTime.Now.Hour *
        3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
        3 Minutes in my case then would be 3 * 60 = 180 to add.

        If this is okay and I can compare that, where is it safest to cancel the order after 3 Minutes? I would assume I only cn do this in the OnBarUpdate() loop, as this is the only loop refreshed every tick (and hoping that one tick after the other would not take longer then my 3 minutes).

        Comment


          #5
          Hi BillCh, the ToTime method will produce an integer representing time so you can go ahead and directly add / subtract like Josh has shown from it.

          You can cancel the order then with CancelOrder - http://www.ninjatrader-support.com/H...ncelOrder.html
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by larkmail, Today, 12:30 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by omermirza, Today, 12:39 PM
          0 responses
          5 views
          0 likes
          Last Post omermirza  
          Started by Danila, Today, 11:08 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by dbida001, Today, 10:31 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by Brandon9821, Today, 08:27 AM
          3 responses
          29 views
          0 likes
          Last Post Brandon9821  
          Working...
          X