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/ Account Name

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

    OnPositionUpdate/ Account Name

    Hello. I'm trying to add some logic to compare Account Positions to Strategy Positions. I'm calling from the OnPositionUpdate, using following parameters:

    protected override void OnPositionUpdate(XXXXXX.Position position, double averagePrice, int quantity, XXXXXX.MarketPosition marketPosition)

    where XXXXX is what I think is live account name (this is what is displayed in the simulations tab). When I do this, I get the following error:

    "The type or namespace XXXXXX cannot be found...."

    Do you know what the issue is? Is there a way for me to Print the account name so I can see what it should be?

    Thanks much.

    #2
    Hello stewarco,

    Thanks for your post.

    Please use the syntax given in the Help Guide to properly override OnPositionUpdate.

    OnPositionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

    If you want to check the position of the account, please use PositionAccount

    PositionAccount - https://ninjatrader.com/support/help...ionaccount.htm

    If you want to print out the name of the account, you can print Account.Name.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      thank for quick response. I think i know what problem is, but maybe you can advise me:

      The Account.Name that is returned is "Backtest", presumably because I'm running the script in the Strategy Analyzer.
      When I'm running in Realtime, I'll be using my actual account.
      Is there a "generic" name I can pass to the OnPositionUpdate such that whatever account is being used at the time (e.g.. Backtest, Sim, {actual account} is recognized, or do I just need to change the passed account name depending on whether I'm testing or live?

      Comment


        #4
        Hello stewarco,

        OnPositionUpdate will show position updates for the strategy position. If the strategy position is in sync with the account position, then the position updates you see in OnPositionUpdate will be consistent with the account/instrument you applied the strategy against.

        OnPositionUpdate is overridden and you will not be able to change its parameters.

        Please let us know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Ok, maybe I'm asking the wrong quesion.
          What I'm trying to do is compare the actual (Account) positions and the Strategy positions as a safeguard.
          So I guess my question is, how do I retrieve the Account position (held at the broker) vs how do I retrieve the Strategy position?

          Comment


            #6
            Hello stewarco,

            If you want to check the position of the account, please use PositionAccount

            PositionAccount - https://ninjatrader.com/support/help...ionaccount.htm

            If you want to check the position of the account, please use Position

            Position - https://ninjatrader.com/support/help.../?position.htm
            JimNinjaTrader Customer Service

            Comment


              #7
              Thanks Jim. The reason I'm asking you is because I have already read all those links extensively and am still getting errors trying to pass an account name into "On Position Update". This take me back to my original question about "Type or namespace cannot be found", even though I'm passing the same account name that i get when I Print Account. Name. If you're saying you haven't encountered this error before in this context I'll just go back to debugging, I just thought maybe someone had encountered something similar in the past.

              Comment


                #8
                Hello stewarco,

                OnPositionUpdate is overridden. You can't change its parameters and you wouldn't pass an account name to it. You will have to use the syntax specified in the help guide.

                If you check PositionAccount, you will be checking the position of the account. If you want to subscribe to account level position updates, you can subscribe to the Account.PositionUpdate event. This will show account level position updates, when the strategy's OnPositionUpdate will show position updates for the strategy position. I've attached an indicator that can show you how you can subscribe to the Account.PositionUpdate event.

                Account.PositionUpdate - https://ninjatrader.com/support/help...tionupdate.htm
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #9
                  I have a quick question about this callback, one of the variables passed into the callback is "quantity" and another is "averageFillPrice"... are these the values for the strategy as a whole or are they only the relative values for the last change?

                  I am confused here because there is also a variable "position" which is an object that seems to contain those same values. So if I compared position.AveragePrice to averageFillPrice, would they always be the same? and what about position.Quantity, is it always the same as quantity?

                  (I am only talking about while I am in the callback function "OnPositionUpdate".

                  Thanks,

                  Jon

                  Comment


                    #10
                    Hello Jon,

                    The linked documentation from post #8 refers to account level position updates. Using OnPositionUpdate in a strategy reflects PositionUpdates that are filtered for the strategy specifically.

                    Quantity reflects the quantity of the change, marketPosition reflects the direction of the change, averageFillPrice would reflect the average entry price of that position. The position parameter reflects the position object itself that is up to date.

                    The last example of the OnPositionUpdate documentation page explains the difference between the position parameter and the other parameters in OnPositionUpdate. In this snippet, the link to Multi Threading Considerations elaborates on the differences between the passed object and the parameters of the OnOrderUpdate/OnExecutionUpdate/OnPositionUpdate methods.



                    Please let us know if you have any additional questions.
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by gemify, 11-11-2022, 11:52 AM
                    6 responses
                    803 views
                    2 likes
                    Last Post ultls
                    by ultls
                     
                    Started by ScottWalsh, Today, 04:52 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by ScottWalsh, Today, 04:29 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by rtwave, 04-12-2024, 09:30 AM
                    2 responses
                    22 views
                    0 likes
                    Last Post rtwave
                    by rtwave
                     
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    5 responses
                    70 views
                    0 likes
                    Last Post tsantospinto  
                    Working...
                    X