Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how do I check if my account has positions open from a strategy?

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

    how do I check if my account has positions open from a strategy?

    Is there a way to check if my account has open trades/position from within a strategy that are either ATM orders or manual orders?

    Thanks,
    joe

    #2
    Hello joejoeagogo,

    Thanks for your post.

    You could use the Account class <Account>.Positions collection to get the position of an account.

    See this help guide page for information about the Account class and sample code: https://ninjatrader.com/support/help...ount_class.htm

    Looping through the Account.Orders collection for the account could be done to find active orders.

    Subscribe to Account OrderUpdate events to look for any newly opened orders. Subscribe to Account PositionUpdate events to see position updates on the account.

    Account.Positions: https://ninjatrader.com/support/help...ns_account.htm

    Account .PositionUpdate: https://ninjatrader.com/support/help...tionupdate.htm

    Account.Orders: https://ninjatrader.com/support/help...rs_account.htm

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

    Let me know if I may assist further.​​
    <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
      Hi Brandon,

      I am reworking some stuff and came across this post so wanted to get your input on what I am trying to do.

      I have two strategy codes for the same instrument (ES) that I want to run on single account. There is a possibility of one getting triggered when there could be a trade already from another strategy at the same time. I am trying to avoid that situation by not executing the trade from Strategy2 if a trade on ES is already on from Strategy1 or vice versa i.e. not take the trade on Strategy1 if Strategy2 already has triggered and has a trade on.

      Do both strategy codes have to check (in its code) whether Account.Positions object array is empty (after initiating an account that matches the account name)

      if (State == State.SetDefaults)

      {

      // Find our Sim101 account

      lock (Account.All)

      myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");

      }


      and then execute a trade from a strategy only if meets that criteria?What's the best way to do this? wanted to make sure

      Thanks
      Last edited by vpatanka; 08-02-2023, 04:01 PM.

      Comment


        #4
        Hello vpatanka,

        Thanks for your notes.

        If both NinjaScript strategies are enabled on the same account and the same instrument then you could consider checking if PositionAccount.MarketPosition == MarketPosition.Flat to check if the account the strategy is running on is in a flat market position before placing orders.

        This should be done in both of your NinjaScript strategies to ensure that you are not in a strategy position on the account the scripts are running on.

        See this help guide page for more information about PositionAccount.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

        See this forum thread for detailed information about running two NinjaScripts on the same account/instrument combination: https://forum.ninjatrader.com/forum/...tures-contract
        <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


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello vpatanka,

          Thanks for your notes.

          If both NinjaScript strategies are enabled on the same account and the same instrument then you could consider checking if PositionAccount.MarketPosition == MarketPosition.Flat to check if the account the strategy is running on is in a flat market position before placing orders.

          This should be done in both of your NinjaScript strategies to ensure that you are not in a strategy position on the account the scripts are running on.

          See this help guide page for more information about PositionAccount.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

          See this forum thread for detailed information about running two NinjaScripts on the same account/instrument combination: https://forum.ninjatrader.com/forum/...tures-contract

          Thanks Brandon.

          I have used Position.MarketPosition many times but that only looks for the position from a particular strategy (and not at the account level). I did not know about PositionAccount.MarketPosition. I will check it out. Thanks again

          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