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

<Account>.ExecutionUpdate: access to MarketPosition, Quantity, Average Price.

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

    <Account>.ExecutionUpdate: access to MarketPosition, Quantity, Average Price.

    Hello.

    Is there a way to access actual account position from within ExecutionUpdate event handler?
    I reviewed all ExecutionEventArgs field, and all of them shows only direction and quantity of execution but any - of actual resulting account position:
    e.MarketPosition
    e.Quantity
    e.Execution.MarketPosition


    <int>e.Execution.Position most of time shows correct quantity with sign corresponding actual MarketPosition (e.g. +1 means Long position with Quantity 1; -2 means Short position with Quantity 2). But, from time to time, it shows Quantity too far from reality. And it does not provide any hint about the Average Price.

    e.Account.Positions array provides position before execution.

    Is there a place to see actual position inside ExecutionUpdate handler?


    Thanks in advance.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Account handlers can be assigned to the account.

    Below is a link to the help guide.
    https://ninjatrader.com/support/help...tionupdate.htm

    The Account.Positions can be looped through.


    Strategies have an PositionsAccount collection.
    https://ninjatrader.com/support/help...ionaccount.htm
    https://ninjatrader.com/support/help...onsaccount.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello, Chelsea
      Thank you for the answer.

      ExecutionUpdate help guide section do not retrieve position properties inside code example.
      Account.Positions array on ExecutionUpdate event contains obsolete information.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Hello fx.practic,

        OnExecutionUpdate() runs when there is an execution (a fill) not when the position updates. The strategy position updates from OnPositionUpdate(). That would be an appropriate time to check the position.


        The Account position will be updating separately. There is no example of checking the account position in OnExecutionUpdate() as this updates separately.

        What obsolete information information in the help guide are you referring to?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I mean "obsolete position information".

          For example, there is Long, 2 contracts opened position.
          Then one contract short execution happened.
          When ExecutionUpdate event triggers, Account.Positions is still Long 2.
          And Long 2 is "obsolete", because actual position is Long 1 now.

          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            The Account position will be updating at a different time. If you want the position when the position is updated, then assign a handler to the <Account>.PositionUpdate event when the position updates.

            OnExecutionUpdate is not an appropriate place to look for position changes.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes, it's clear now, thank you.

              And is this guaranteed sequence ExecutionUpdate -> PositionUpdate for all connections, all brokers and accounts?
              I am just need both: updated position and execution name to take actions in code.

              Now I am reading <Account>.Executions.Last().Name inside PositionUpdate event handler.
              Is this correct and versatile?
              fx.practic
              NinjaTrader Ecosystem Vendor - fx.practic

              Comment


                #8
                Hello fx.practic,

                These events are triggered when the events happen. There is no guarantee the order, and your code should never be written to rely on the order of the events.
                good day together, i have now spent 2 days on this and other forums looking for a solution to my problem and hope to get an answer to my question here ;-) the following scenario in unmanaged mode: -----------------------------------------------------------------------------------------------------------------------------------


                Instead the code should be event based, and object based. Store information to bools and doubles if you need multiple events to occur (in any order) before triggering an action.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks a lot, Chelsea.
                  Andrii.
                  fx.practic
                  NinjaTrader Ecosystem Vendor - fx.practic

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  16 responses
                  3,279 views
                  0 likes
                  Last Post Leafcutter  
                  Started by WHICKED, Today, 12:45 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post WHICKED
                  by WHICKED
                   
                  Started by Tim-c, Today, 02:10 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Taddypole, Today, 02:47 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Taddypole  
                  Started by chbruno, 04-24-2024, 04:10 PM
                  4 responses
                  51 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Working...
                  X