Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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([COLOR=#0000ff]int[/COLOR] [I]barsInProgressIndex[/I], [COLOR=#0000ff]bool[/COLOR] [I]liveUntilCancelled[/I], [COLOR=#0000ff]int[/COLOR] [I]quantity[/I], [COLOR=#0000ff]double[/COLOR] [I]limitPrice[/I],[COLOR=#0000ff]string[/COLOR] [I]signalName[/I])
    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 gravdigaz6, Yesterday, 11:40 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by XXtrader, Yesterday, 11:30 PM
          0 responses
          4 views
          0 likes
          Last Post XXtrader  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Yesterday, 09:43 PM
          0 responses
          9 views
          0 likes
          Last Post funk10101  
          Working...
          X