Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Extracting order's age

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

    Extracting order's age

    I'm trying to extract the age of the orders in OnBarUpdate(), i.e. the time since the last Sending / Modification / Cancellation occurred.
    My current solution is to 'catch' the order in OnOrderUpdate() (i.e. to copy a reference to it to a private field), then in OnBarUpdate(), I access the 'Time' property of the order, which, according to the manual is
    A DateTime structure representing the last time the
    order changed state
    .
    This solution seems to work just fine in backtest / simulation, but not in live trading.

    My questions:
    1. What is the cause of discrepency between the simulation and live trading in this case?
    2. Is there another way of acheiving what I need?


    Thanks,

    Boaz

    #2
    boaza,

    I am happy to assist you.

    In backtesting the time stamps are only based on the time of the bar, this is the most granularity you have for orders. There is no awareness of any other time than these times.

    What discrepancies are you seeing? It is helpful to run print statements to see if things are behaving as you expect, i.e. variables are updating, orders are submitting, etc.

    Please let me know if I can assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,
      What I'm seeing is the the order's age is very short compared to simulation (I'm talking about a limit order). However, the limit price was not changed for a long time. I'm using the managed approach, and AFAIK NinjaTrader will not send an update for an order if its parameters (limit,size etc.) has not changed.

      So let me rephrase:
      Will the Time property of an order reflect the last time a message has been sent to the broker to update the order?

      Thanks,
      Boaz

      Comment


        #4
        So let me rephrase:
        Will the Time property of an order reflect the last time a message has been sent to the broker to update the order?

        Yes, or the last time you get an update back from the broker as well. Such as Filled/Cancelled/Rejected/Modified etc.

        Comment


          #5
          Hi Brett,
          The order.Time seems to be correct for live trading, but not for simulation. For example, see the following printout:
          03/01/2008 21:30:00, Entry, NT-00000, Limit, PendingSubmit, SellShort, 1.4758, 0, 03/01/2008 21:30:00
          03/01/2008 21:30:00, Entry, NT-00000, Limit, Accepted, SellShort, 1.4758, 0, 03/01/2008 21:30:00
          03/01/2008 21:30:00, Entry, NT-00000, Limit, Working, SellShort, 1.4758, 0, 03/01/2008 21:30:00
          03/01/2008 21:42:00, Entry, NT-00000, Limit, PendingChange, SellShort, 1.4757, 0, 03/01/2008 21:30:00
          03/01/2008 21:42:00, Entry, NT-00000, Limit, Accepted, SellShort, 1.4757, 0, 03/01/2008 21:30:00
          03/01/2008 21:42:00, Entry, NT-00000, Limit, Working, SellShort, 1.4757, 0, 03/01/2008 21:30:00
          The time stamp on the left is the current bar time (Strategy.Time[0]). The time stamp on the right is IOrder.Time.
          It is clear that even though the order changed states (and limit prices), the IOrder.Time still refers to the first time the order was placed.

          Any ideas how to overcome this?

          Thanks,

          Boaz

          Comment


            #6
            boaza,

            I just wanted you to know I am currently looking into this further.

            One issue I am seeing that is totally expected is that even in live trading, Time[0] only has resolution to the period of the chart, i.e. if you are on a 1 minute chart you won't see seconds matching all the time on your order time.

            I'm constructing some code for test output and I'll get back to you as soon as I can.

            I look forward to assisting you.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              boaza,

              I believe that the IOrder objects do not update their time stamp until after a fill, and fills call the OnExecution() method, so you will be delayed when accessing IObjects here. This being the case, you can use the IExecution object in the method OnExecution(IExecution execution) to get yourself the closing time of the IOrder object. I.e. execution.Time.

              OnExecution() : http://www.ninjatrader.com/support/h...nexecution.htm

              IExecution : http://www.ninjatrader.com/support/h...iexecution.htm

              I have attached a simple example of some code I added to a strategy that only enters longs you can use to see what I am talking about. It has plenty of print statements you can look at in the Output Window to illustrate what I am talking about.

              Please let me know if I can assist further.
              Attached Files
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Thanks Adam, I'll have a look.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                191 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,230 views
                0 likes
                Last Post xiinteractive  
                Working...
                X