Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position object is not updated

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

    Position object is not updated

    Hello,

    I attach a custom log to check the execution of my strategy in NT7B14.
    CalculateOnBarClose = false;
    Unmanaged = true;
    TraceOrders = true;

    (Please, see the image).

    Point 1.- In this moment there is a buy stop order working. These three prints are in the OnOrderUpdate method.

    Point 2.- A moment later, one new tick arrives, and the OnBarUpdate method is executed.
    Here, the execution is in the OnBarUpdate method.
    Coincidentally, the order has been filled at the same time. The order object is updated (his OrderState == Filled). Correct.
    (Before passing to the OnOrderUpdate method, all code of the OnBarUpdate method must be executed. Correct).
    The order object has been updated, but the Position object does not !!!

    (After, the execution passes to the OnOrderUpdate method and after to the OnExecution method and after to the OnPositionUpdate method. Correct).

    I hope I explained clearly.

    Thanks

    Edit: LiveTrading with Interactive Brokers
    (In simulation this bug does not occurs)
    Attached Files
    Last edited by cls71; 04-16-2010, 10:25 AM.

    #2
    Hello,

    Just wanted to let you know we recieved your note and someone will answer shortly.

    Thank you for your patience.
    BrettNinjaTrader Product Management

    Comment


      #3
      cls71,

      Not sure I am following your sequence of events, but this is what is expected to happen.

      OnOrderUpdate > OnExecution > OnPositionUpdate. Only after receiving an OnPositionUpdate event would you have your position object updated. Accessing the IOrder object before then will yield the order saying filled, but without a position update event you will not have a position as defined by the position object yet.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Hello Josh,

        the issue is not with the event sequence.

        I explain in the attached image.

        Thanks

        PD: only occurs in live trading.
        Attached Files

        Comment


          #5
          cls71,

          That is correct. You can have the IOrder updated, but the IPosition not updated yet. Depending on when you access things this can occur. The IPosition would only be updated after you receive an OnPositionUpdate() event.

          It is just like how in OnExecution you can have the underlying IOrder of the execution show as Filled even though you are still only processing the first IExecution from that order when there were multiple partial fills. NT is multi-threaded and things can be asynchronous.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            cls71,

            The IPosition would only be updated after you receive an OnPositionUpdate() event.
            Thanks Josh,

            then why the IOrder is updated before I receive an OnOrderUpdate() event ?
            IPosition and IOrder have a different behaviour. It is not understandable.

            Comment


              #7
              cls71,

              That is the nature of being multi-threaded. If OnBarUpdate() interjects and throws an event, while your computer is processing that event if the IOrder is updated then you get an updated IOrder object in OnBarUpdate(). Getting an updated IOrder does not mean it was able to go all the way through and get you an IPosition as well. Remember the process is Order>Execution>Position. When you get an OnBarUpdate() and then you get a race condition of the IOrder while it is processing, just because the IOrder finished doesn't mean the execution and position also finished while you are still computing OnBarUpdate(). Position checks in OnBarUpdate() should only be relevant after the OnPositionUpdate() event.

              What I will do is check with development to ensure that this is in fact expected race conditioning, but I do believe this can be the case.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thanks Josh,

                I deeply regret not speak in English fluently.

                I do not know the internal implementation of the multi-threading in NinjaTrader, or as it implements the communication with the broker. But I think if a IOrder reference variable is updated immediately should be updated the IPosition reference variable.

                The IOrder reference variable can be updated in a thread. And the IPosition reference variable can be updated in another thread. But both threads should be synchronized.

                Another different issue is the order in which events are executed: OnOrderUpdate, OnExecution and OnPositionUpdate.
                But this has nothing to do with the time when the properties of the reference variables are updated. The properties may be updated long time before the corresponding event runs.

                Regards

                Comment


                  #9
                  Hello,

                  some new thing about this issue ?

                  Thanks

                  Comment


                    #10
                    Hi cls71,

                    Thanks for posting, someone will reply later today, thanks for your patience.
                    TimNinjaTrader Customer Service

                    Comment


                      #11
                      cls71,

                      Thank you for your patience. I have confirmed with development my earlier posts information is accurate. This is just the nature of asynchronous events.

                      It is possible to get the events after the properties update because the OnOrderUpdate()/OnExecution()/OnPositionUpdate() would come only after the underlying object has changed. That would not necessarily change for all 3 at the same time which is what you are experiencing. Only way to confirm you receiving all is to wait for after OnPositionUpdate() when you would be guaranteed the sequence is complete.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank Josh,

                        then the property "Position.MarketPosition" is not useful within the method "OnBarUpdate."

                        It is within the method "OnBarUpdate" where I get my entry signals, and where I have to submit the orders to enter to the market. But first I have to know what my "Position.MarketPosition" and it may be that this property is not trusted.

                        I try to find a solution.


                        Thanks very much.

                        Comment


                          #13
                          cls71,

                          To clarify, it is only guaranteed to provide you positioning in the OnBarUpdate() after you receive an OnPositionUpdate() event. Anything that comes before that, will need to be addressed in your code due to asynchronous events.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          601 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          347 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          103 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          559 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          558 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X