Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPositionUpdate

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

    OnPositionUpdate

    Hi,

    I am having an odd issue with OnPositionUpdate. I have checked my code and cannot seem to find a way it could be the issue but isn't this so often the case with a bug?

    I just want to make certain there isn't a known issue or operating characteristic I don't know about before I spend a lot more time on this.

    I am getting a call to OnPositionUpdate with zeros across the board (AvgPrice = 0, flat, quantity = 0) just prior to an execution giving me my first position after previously being flat.

    The sequence is: OnPositonUpdate because of an exit taking me flat then an execution giving me a position resulting in a call to OnPositionUpdate with the zero values, then the expected OnPositionUpdate execution showing me with an open position... then after exiting the position, the OnPositionUpdate appropriately showing me flat.

    This scenario seems like it has to be in my code but I do not see how. If someone can verify this isn't a known characteristic I will head back to the salt mine of 7 million print statements...

    Thanks in advance
    Scott

    #2
    Hello Scott,
    Thanks for your post and I am happy to assist you.

    When the MarketPosition is Flat then AvgPrice and Quantity will be 0 (zero) this is the expected behavior.

    Let me exemplify the sequence.
    You enter long trade – OnPositionUpdate (OPU) MarketPostion – Long; AvgPrice- will have value; Quantity will have value;
    You go short (EnterShort) – OPU’s market position will first go flat (avgprice and quantity will be 0 (zero)), and then market position will be Short, Avgprice will have value and quantity will have value.
    You exit the short (ExitShort) – OPU’s market position will go flat (avgprice and dquantity will be 0 (zero)).

    Please do let me know if I can assit you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Joydeep,

      Thanks for getting back to me so quickly. I may have not been clear in the sequence I am seeing.

      Start with the strategy being flat and everything in sync such as would be the case upon starting a strategy.

      As soon as I get an execution, I am getting 2 OnPositionUpdate calls; one showing me flat (which I am not), immediately followed by a call showing me with 1 position (which is correct). It is the first call showing me flat that has me baffled.

      Once I am flat again, I get the proper call to OnPositionUpdate showing me flat (as expected) but once I get a new position I am again getting the phantom call to OnPositionUpdate.

      At the front of every sequence I am getting one call showing me flat that is apparently triggered by my first exection after being flat.

      The problem is I cannot tell the difference between the end of trade call showing me flat and the phantom call showing me flat without writing more code. In some ways it doesn't hurt anything because I immediately get the second call showing me (correctly) with one position.

      Since this is production code, I track down absolutely every anomaly to ensure I don't have a bug in my own code.

      Best Regards,
      Scott
      Last edited by ScottB; 01-19-2012, 09:59 AM.

      Comment


        #4
        Hello Scott,
        In Control Center, in the Strategies tag, what is the color of the strategy cell (green/yellow). If its yellow, then the strategy is waiting to get flat. And as such when a signal is generated, you will first get and Flat MarketPositon, and then a Long/Short MarketPositon in the OnPositionUpdate.

        Please do let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Joydeep,

          Thanks for the update; because this is in a running strategy, it all appears to happen almost simultaneously looking at the screen but I will try watching more closely. I assume there are no known issues surrournding this behavior and all is as expected.

          At this point, I will put in the print statements to make certain I am not causing this and also try watching the strategyies tab to see if I can discern what you are describing.

          Thank you for your assistance.

          Best Regards,
          Scott

          Comment


            #6
            Hello Scott,
            When you restart the strategy do look into the strategy cell color (in Control Center).

            Also while debugging, do use the Print statement, if you still feel there is an issue, then send the steps to reproduce the issue, along with a sample code and with the Print statements.

            I look forward assisting you.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Joydeep,

              I just realized, you meant check the strategy color as soon as I enable the strategy to see if it thinks there is a position at the transition from historical data. If that is what you are talking about, I have already done that and no it doesn't, it starts flat always (for this strategy I don't allow trading on historical data).

              Best Regards,
              Scott

              Comment


                #8
                Hello Scott,
                Can you post a sample script (or send it to support[AT]ninjatrader[DOT]com with Attn Joydeep in the subject line with the reference to this thread) and the Print logs so that I could check the same. Also do let me know the exact steps to replicate the issue.

                I look forward assisting you.
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                639 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                572 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X