Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

All Positions For All Strategies

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

    All Positions For All Strategies

    NT,
    Can you help me with some code for NT8 as I am not understanding how to call all open positions.
    I have been reviewing the following:


    I have a max # of positions that I would like to limit my strategy to having open. This strategy is a multi instrument strategy.

    How can I call all open positions between all instruments in the account?
    If the account has 5 long trades I would like to be able to return that 5 trades are open.

    Is there a method to call this? I have read that you need to loop through all account.positions... is that right? How do you loop through these and return the logic I desire.

    Thanks.

    #2
    Something similar to this for NT8?


    if (BarsInProgress == i
    && Positions[i].Account.Positions.Count > 0)

    Comment


      #3
      Hello Cpuerta,

      Thanks for your inquiry.

      NinjaScript strategies are designed to manage their own positions and are not designed to manage other strategy positions. AddOn code could be added to a NinjaScript strategy where you can have logic manage each position in Account.Positions, and then use the Account ExecutionUpdate and OrderUpdate events to manage those positions. However this approach would not be supported in the context of a strategy and could adversely affect the behavior of your other strategies.

      Our recommendation would be to design a multi instrument strategy that adds a data series for each instrument you would like the strategy to manage, and then use the Positions[] array to manage the position of each data series added to the strategy.

      I've included links to the Multi Time Frame and Instruments documentation for a complete reference for using a multi instrument NinjaScript and a link to the Positions array which would be used to reference each position for the instruments added.

      Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

      Positions - https://ninjatrader.com/support/help.../positions.htm

      If you simply wish to observe what position the account is in for an instrument added by the strategy, you could use PositionsAccount.

      PositionsAccount - https://ninjatrader.com/support/help...onsaccount.htm

      If your goal ultimately depends on managing account positions outside of the context of a strategy, you may refer to the links below for the code that could be used to accomplish. As this would be unsupported, please understand that there are several other implications to consider which we could not assist with further.

      Account.Positions (example to loop through included) - https://ninjatrader.com/support/help...ns_account.htm

      Account.ExecutionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

      Account.OrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

      Please let us know if we can be of further assistance.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X