Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position account

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

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

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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

    Leave a comment:


  • elliot5
    replied
    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");
    }

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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);
    		}
    	}
    }

    Leave a comment:


  • elliot5
    replied
    This is an NT 7 question..sorry forgot to mention it. Regards

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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.

    Leave a comment:


  • elliot5
    replied
    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.

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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)
         .....
    }

    Leave a comment:


  • bergimax
    replied
    Than's ZacharyG!

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

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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

    Leave a comment:


  • bergimax
    replied
    Here there is a simple script with create the error!

    Thank's for the assistance!
    Attached Files

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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.

    Leave a comment:


  • bergimax
    replied
    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?

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    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.

    Leave a comment:


  • bergimax
    started a topic Position account

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by gbourque, Today, 06:39 AM
2 responses
13 views
0 likes
Last Post gbourque  
Started by rexsole, Today, 08:39 AM
0 responses
4 views
0 likes
Last Post rexsole
by rexsole
 
Started by trilliantrader, Yesterday, 03:01 PM
3 responses
30 views
0 likes
Last Post NinjaTrader_Clayton  
Started by cmtjoancolmenero, Yesterday, 03:58 PM
4 responses
26 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by Brevo, Today, 01:45 AM
1 response
14 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X