Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alifarahani, Today, 09:40 AM
      6 responses
      31 views
      0 likes
      Last Post alifarahani  
      Started by Waxavi, Today, 02:10 AM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Kaledus, Today, 01:29 PM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Waxavi, Today, 02:00 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      17 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X