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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      120 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      72 views
      0 likes
      Last Post PaulMohn  
      Working...
      X