• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

earliest event for querying account positions?

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

    earliest event for querying account positions?

    In what event is the earliest place I can safely query the account positions to see what positions are open?

    #2
    Hello NinjaCustomer,

    Thank you for the question.

    Can you provide more details on the context of where you are wanting to check the position? Is this from an addon or another type of script?

    The earliest you can execute code will depend on the type of script use in addition to what Account object we are referring to here.

    If you mean the Addon account which you locate, the earliest you can access the Positions would be after finding the account and assigning it to a variable. The scope where that is used also matters. If this was a Strategy that could be used anywhere from State.SetDefaults and on really. If this is a custom addon, that really depends on the context of what you made, without details on where you are trying to execute this I would likely be unable to answer this question with any accuracy.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      it is from an addon - I'm not sure what account object, just want to query positions on the current account.

      Comment


        #4
        Hello NinjaCustomer,

        Thank you for your reply.

        Have you at this point reviewed the addon samples that we have in the help guide surrounding accessing an account?:
        https://ninjatrader.com/support/help...ount_class.htm

        Or the full addon sample you can import which is also in the help guide?:
        https://ninjatrader.com/support/help...t_overview.htm

        Both of these samples demonstrate accessing an account however without more detail about your specific question I don't know if I could be of further assistance.

        An addon by default has no account, you would need to implement an account picker if you are using a GUI add-on, or use the syntax from the first to find an account by its string name. In both situations, you have an account object which has sub-methods and collections. Here is another example using the string name for finding an account and accessing the positions from the account object:
        https://ninjatrader.com/support/help...ns_account.htm


        In relation to your earlier question, how early this can be accessed depends on your addon. If its a GUI addon, you will likely want to try and replicate what is shown in the addon sample for its account picker. If you have some other type of non-gui addon or something that affects other windows you will need to review your logic to see where this may best fit in.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          here is my predicament

          currently my addon does not loop positions.

          instead it uses
          OnPositionUpdate() however I have no idea what account that is.. I've been testing it only on a SIM account. I want to make it so that if I restart NT8 then I can check the existing positions. I want to do this at the earliest possible moment where this data would be available. Maybe on a SIM that is immediately? but I think on a live account you should wait until the account is connected? if I check it too early I assume it would just show no positions.

          Comment


            #6
            Hello NinjaCustomer,

            Thank you for your reply.

            however I have no idea what account that is
            This is something you would need to review with what you have coded so far.

            It sounds like you created something which has logic to get an account already because your observing OnPositionUpdate which requires an account to observe. This may be an account picker or the string example I previously provided which is getting the account in your script. You have not provided any information about your addon at this point so I am unsure what you may have coded so far. If you can provide more information about your addon and the syntax you used, that would be helpful as I am just guessing based on your description here.

            I want to make it so that if I restart NT8 then I can check the existing positions
            You can do that, but this again depends on what kind of addon you made. Did you make a window? What does your addon do specifically and where in your addons code are you trying to access the account? You will need to review your script and see what you have coded so far, as noted it sounds like you already have an account setup you likely just need to use the Positions collection instead of OnPositionUpdate if you wanted to loop over them.

            If you are trying to wait for a connection to check your account, you could review the addon section of the help guide about using connection information: https://ninjatrader.com/support/help...atusupdate.htm

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              yes you are right.. it searches for the SIM account and then adds the onPositionUpdate...

              no windows are created..

              well, I mean I don't need to wait for a connection if it will already be populated with the last known positions.. is that what will happen? if I check the positions before the connection is successful?

              Comment


                #8
                Hello NinjaCustomer,

                I had mentioned the connection status because a live account would not be available if you are not connected or on a different connection than the connection is associated with. The positions collection will be available if you find the target account and access the positions. If you check for the live account before you are connected it is likely you would not find the account and not be able to check the positions.

                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  is it really necessary to -= OnConnectionStatusUpdate or
                  -= OnPositionUpdate? in OnCleanup() I'm not sure if it will be fired since I create no windows or tabs in my addon

                  I don't seem to have any Cleanup() to override

                  namespace NinjaTrader.NinjaScript.AddOns
                  {
                  public class MyAddon : NinjaTrader.NinjaScript.AddOnBase
                  Last edited by NinjaCustomer; 03-14-2019, 01:59 AM.

                  Comment


                    #10
                    Hello NinjaCustomer,

                    Thank you for your reply.

                    Yes, you do need to unsubscribe from open event handlers. You haven't provided enough detail about your addon for me to point a direction here, you would need to provide more of a sample of where you are setting up the account in your addon.

                    If you don't have a window, where are you checking the account? Are you using OnWindowCreated in some way to do this?

                    However you have created your addon, you will need to implement some kind of cleanup to clean the events you use up. If you are using the addon in a basic way from OnWindowCreated, you can use the addons OnStateChange to handle the addons lifecycle and cleaning of objects.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      yes it was using OnWindowCreated, now I've moved that code to
                      OnConnectionStatusUpdate() (and use a flag so I don't execute my init code more than once) what state in OnStateChange should I use?

                      Comment


                        #12
                        Hello NinjaCustomer,

                        For more information about OnStateChange please see the OnStateChange documentation: https://ninjatrader.com/support/help...=OnStateChange

                        State.Terminated would be when the addon terminates.

                        Please let me know if I may be of additional assistance.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jjnc2006, Today, 07:36 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post jjnc2006  
                        Started by futurenick, Today, 06:26 AM
                        1 response
                        11 views
                        0 likes
                        Last Post nkhoi
                        by nkhoi
                         
                        Started by NinjaCustomer, Today, 12:29 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ShawnB  
                        Started by Steve L, Today, 11:32 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post Steve L
                        by Steve L
                         
                        Started by prabbala, Today, 10:41 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post prabbala  
                        Working...
                        X