Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible for a strategy to obtain the number of open positions on an account?

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

    Is it possible for a strategy to obtain the number of open positions on an account?

    Hello,

    Is it possible to have a strategy only make a trade if there are currently zero open positions on an account? Or if the account's buying power is a certain amount? If so how?

    Can this be done via an indicator that the strategy utilizes?

    #2
    Hello burmaz,

    Thanks for your post.

    You could create a condition that checks if PositionAccount.MarketPosition == MarketPosition.Flat to detect if an account is in a Flat position in a strategy.

    The account Positions collection could be used to get the MarketPosition of an account in an indicator.

    Account.Get() could be used to get an AccountItem value for an account, such as the buying power (AccountItem.BuyingPower).

    See the help guide documentation below for more information.

    PositionAccount.MarketPosition: https://ninjatrader.com/support/help...etposition.htm
    Account: https://ninjatrader.com/support/help...ount_class.htm
    Account.Positions: https://ninjatrader.com/support/help...ns_account.htm
    Account.Get(): https://ninjatrader.com/support/helpGuides/nt8/get.htm
    AccountItem: https://ninjatrader.com/support/help...ccountitem.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Yes, using the account object you can obtain all of the open positions for an account. That would be true in an indicator or add-on as well, not just in a strategy.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Originally posted by burmaz View Post
        Hello,

        Is it possible to have a strategy only make a trade if there are currently zero open positions on an account? Or if the account's buying power is a certain amount? If so how?

        Can this be done via an indicator that the strategy utilizes?
        Yes. You could use something like Account Position == Flat.

        Comment


          #5
          Assuming your strategy code is in a section that is about to execute a trade, this will work avoid the execution if the account is not flat. Of course, it will return on the first position found, but that is fine.

          // Do not execute if not flat.
          string accountName = Account.Name;
          Account account = Account.All.FirstOrDefault(a => a.Name == accountName);
          lock (account.Positions)
          {
          foreach (Position position in account.Positions)
          {
          return;
          }
          }​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          46 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
          66 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