Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position account

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

    Position account

    Hello, i have some question about Account.Position.

    How can i know the account position of my second account?
    And, how can i use this position in my strategy, for example in bar update?

    Thank's in advance for the assistance,

    Bergimax

    #2
    Hello bergimax,

    Thank you for writing in.

    You can access the positions of your secondary account by utilizing the Positions collection.

    More information about using this collection can be found in the help guide here: http://ninjatrader.com/support/helpG...ns_account.htm

    If you would like to check if the market position of a position at index 0 is long, for example:
    Code:
    if (secondAccount.Positions[0].MarketPosition == MarketPosition.Long)
         // do something
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Using this, i have this error:
      "Error on calling 'OnBarUpdate' method on bar 73940: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

      Where i wrong?

      Comment


        #4
        Hello bergimax,

        Can you provide your script, or a sample script, that demonstrates this issue so I may investigate further?

        To export your script, please follow the instructions below:
        • From the Control Center window select the menu Tools > Export > NinjaScript... to open the "Export NinjaScript" dialog window
        • Press "add"
        • Use the "Type" drop down to filter available NinjaScript types
        • Select all of the files that you want to export and press the "OK" button
        • A list of all files that will be exported will be shown
        • Press the "Export" button to export the selected files
        • A NinjaScript Archive File (.zip) file will be created in My Documents\<NinjaTrader Folder>\bin\Custom\ExportNinjaScript. You can press ".." and change the export directory if you wish


        Once you have exported the script, please attach the ZIP file to your reply.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Here there is a simple script with create the error!

          Thank's for the assistance!
          Attached Files

          Comment


            #6
            Hello bergimax,

            You'll want to make sure a position exists first before trying to access it.

            For example:
            Code:
            if (myAccount.Positions.Count > 0)
                 // do something
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Than's ZacharyG!

              But if i use " myAccount.Positions.Count > 0 " the strategy never taking the first position. Why?

              Comment


                #8
                Hello bergimax,

                Please only utilize this check before accessing Positions[0]. You do not want to wrap your entry logic in this statement.

                For example:
                Code:
                if (myAccount.Positions.Count > 0)
                {
                     if (myAccount.Positions[0].MarketPosition == MarketPosition.Flat)
                     .....
                }
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Accessing Account position

                  Can you please confirm that:

                  && Account.Positions[i].MarketPosition == MarketPosition.Flat

                  will detect if there is an account position in barsinprogress instrument i ... and not any
                  instrument position in the account.



                  I am finding that the following code does not differentiate between any account position and an individual barsinprogessindex position:

                  && Positions[i].Account.Positions.Count == 0

                  Regards and pls remove the member who answered above. Life is hard enough.
                  Last edited by elliot5; 07-21-2016, 03:17 AM.

                  Comment


                    #10
                    Hello everington_f,

                    Account.Positions[i] is going to give you whatever account position is at index i; this is not affected by added series in your strategy. Account.Positions holds all Position objects generated for the account.

                    You will need to use PositionsAccount: http://ninjatrader.com/support/helpG...onsaccount.htm

                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      This is an NT 7 question..sorry forgot to mention it. Regards

                      Comment


                        #12
                        Hello everington,

                        Accessing account positions from a script is not a documented feature for NinjaTrader 7.

                        You will want to loop through all account positions and print out each position's Instrument property to find out what instrument each account position is for.

                        Example:
                        Code:
                        foreach (Account acct in Cbi.Globals.Accounts)
                        {
                        	if (acct.Positions != null)
                        	{
                        		PositionCollection positions = acct.Positions;
                        		foreach (Position pos in positions)
                        		{
                        			Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
                        		}
                        	}
                        }
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ZacharyG View Post
                          Hello everington,

                          Accessing account positions from a script is not a documented feature for NinjaTrader 7.

                          You will want to loop through all account positions and print out each position's Instrument property to find out what instrument each account position is for.

                          Example:
                          Code:
                          foreach (Account acct in Cbi.Globals.Accounts)
                          {
                          	if (acct.Positions != null)
                          	{
                          		PositionCollection positions = acct.Positions;
                          		foreach (Position pos in positions)
                          		{
                          			Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
                          		}
                          	}
                          }
                          The following code uses your idea.. but it is not able to access the flat market position for an instrument... what needs modifying to access the fact that an instrument is flat in the specified account? ( all of this would have been negated if there was a sync strategy position to fit the existing account position).





                          foreach (Account acct in Cbi.Globals.Accounts)
                          {
                          if (acct.Positions == null)
                          {
                          PositionCollection positions = acct.Positions;
                          foreach (Position pos in positions)
                          {
                          if (BarsInProgress == 16
                          && pos.Account.Name == "USSwingStocks")
                          && pos.Instrument.FullName == "COP")
                          && pos.MarketPosition == MarketPosition.Flat)
                          && Momentum(Closes[16],20)[0] < -1)


                          {
                          Print("True");
                          }

                          Comment


                            #14
                            Hello everington_f,

                            The position no longer exists on the account once the the position is closed.

                            You won't be able to pull any position information once the position is closed in NinjaTrader 7.

                            This is supported in NinjaTrader 8 with PositionsAccount and will return flat if no account position exists for any other instruments added in your script: https://ninjatrader.com/support/help...onsaccount.htm
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              Aha so with NT7 there is no real way to break out the MarketFLATPosition for a specific instrument in a specific account....

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X