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

OnPositionUpdate Items

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

    OnPositionUpdate Items

    In an AddOn, OnPositionUpdate provides two "versions" of several items, found in PositionEventArgs and in PositionEventArgs.Position.

    These items are AveragePrice, MarketPosition and Quantity.

    Assuming e is the PositionEventArgs, and tracing Position Updates as follows:

    e.Operation, e.Position.MarketPosition, e.Position.Quantity, "@", e.Position.AveragePrice, "", e.AveragePrice, "➜", e.MarketPosition, e.Quantity

    ... for a single Order Buy (Forex 1K units) followed by an Exit of that Execution at a different price produces this:

    Add Long 1000 @ 0.7145'9 \ 0.7145'9 ➜ Long 1000
    Remove Long 0 @ 0.7145'9 \ 0.7145'9 ➜ Flat 0


    Grateful for confirmation that this is indeed what is expected. (If not, what does that imply?)

    It is somewhat logical to see e.Position.MarketPosition and e.MarketPosition change, although I would have thought that e.Position.MarketPosition in the Add should have been Flat at first.

    It is not clear why AveragePrice and Quantity are the same in both updates.

    Grateful for an explanation of the exact interpretation of each item in each variation. [The Help documentation is not clear on this.]

    Thanks.​
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Hello jeronymite,

    Thanks for your post.

    e.Position is the currently updating position, such as e.Position.MarketPosition / e.Position.Quantity. This is not the actual position of the account.

    e.MarketPosition / e.Quantity is the actual pointed position of the account. The e.Position updates the e.MarketPosition and causes the <account>.PositionUpdate to trigger.

    Please see this forum thread where my colleague Chelsea explains a bit more about this topic: https://ninjatrader.com/support/foru...72#post1061172

    Please let me know if I may assist you further.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, NinjaTrader_BrandonH and also to NinjaTrader_ChelseaB for the information.

      For clarity:
      • The e.Position.* items are the items for the current update of the Account
      • The e.* items are the "post-update" Account position
      • The e.* items update after the e.Position.* items
      Is that correct?

      Some further questions:
      1. In the example e.Position.MarketPosition I gave above for the Remove, presumably it is Long, but with a Quantity of zero, because it is the change from Long to Flat? A little ambiguous perhaps, but I can see the reasoning. It could equally be reasonable to have it as Flat, indicating the change brings it to Flat, given the zero Quantity. That would be my intuitive interpretation. Just confirming the first reasoning here is the intended understanding?
      2. What about the AveragePrice items -- they never vary. Why?
      Thanks.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        Hello jeronymite,

        Thanks for your note.

        It seems your understanding is not correct.

        "The e.Position.* items are the items for the current update of the Account​"

        e.Position is the specific event for the currently updating position, such as e.Position.MarketPosition / e.Position.Quantity. This is not the actual position of the account.

        "The e.* items are the "post-update" Account position"

        This is the actual account value, it is not pre/post updated value. It is just what the value was at that time of the event based on the account values.​

        "The e.* items update after the e.Position.* items"

        The event happens all at once, the values you get inside that event are based on the event that happened and the current account values during that event's time.

        Note that the order of events will be affected by your broker. For example, the order of events would be different when comparing say Rithmic or IB.​

        Overall, you could use prints to see the specific order of events that your broker produces and ensure your logic lines up with the events that the broker you are using has. We do not have more detailed information than this that we could share as more detailed information is not documented.

        Please let me know if I may assist further.
        Last edited by NinjaTrader_BrandonH; 02-02-2023, 04:19 PM.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks, NinjaTrader_BrandonH. My description of my understanding could have been better. Thanks for your clarifications. It is what I thought was the case, despite my poor wording. The additional information about the order of the events and the broker-dependencies is important. Thanks.

          What about AveragePrice?

          Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            Hello jeronymite,

            Thanks for your note.

            e.Position.AveragePrice would be the average price for the currently updating position. This would be the average price for the specific event, not the average price of the actual position of the account.

            e.AveragePrice would be the average price value calculated at that time of the event based on the account values.​

            Let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks, NinjaTrader_BrandonH. I understand. Given my example, I can see why they are all the same. I will explore this more with multiple accounts/instruments/orders.

              Thanks.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kempotrader, Today, 08:56 AM
              0 responses
              6 views
              0 likes
              Last Post kempotrader  
              Started by kempotrader, Today, 08:54 AM
              0 responses
              4 views
              0 likes
              Last Post kempotrader  
              Started by mmenigma, Today, 08:54 AM
              0 responses
              2 views
              0 likes
              Last Post mmenigma  
              Started by halgo_boulder, Today, 08:44 AM
              0 responses
              1 view
              0 likes
              Last Post halgo_boulder  
              Started by drewski1980, Today, 08:24 AM
              0 responses
              4 views
              0 likes
              Last Post drewski1980  
              Working...
              X