Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Find open positions on another account or Instrument in the same account

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

    Find open positions on another account or Instrument in the same account

    I have created a multiple account/instrument strategy . The main chart that has the strategy is the controlling one. So my issue is when the order closes in the main chart ie NQ, and I have an open order that may still be open on ES or NQ on another account. Once the primary NQ closes I need to determine if the other instrument and or account has any open positions. What is the best code to ascertain the other accounts/instruments for open positions .One check to see if a particular account had any open positions and a second request if a certain instrument had a position open

    #2
    Hello set2win,

    Thanks for your post.

    You could use <Account>.Positions to check what the market position is for a specific account.

    See this help guide page for more information and sample code: https://ninjatrader.com/support/help...ns_account.htm

    <Account>.Orders could be used to get a collection of orders on a specific account.

    See this help guide page: https://ninjatrader.com/support/help...rs_account.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
      not having any luck with this. using the code example for Positions I get an error OnStateChange object referenced not set to instance of an object.
      else if(State==State.DataLoaded)
      {
      // Find our Sim101 account
      lock (Account.All)
      Account1 = Account.All.FirstOrDefault(a => a.Name == account1);
      Account2 = Account.All.FirstOrDefault(a => a.Name == account2);
      /// When adding this section I get the error:
      lock (Account1.Positions)
      {
      foreach (Position position in Account1.Positions)
      {
      Print(String.Format("Position: {0} at{1}", position.MarketPosition,position.AveragePrice));
      }
      }
      The main issue is to note when the main strategy no longer has open positions to go ahead and run a Close procedure for the open trades in other account or Instrument. So maybe a bool that notes when state has changed. so when order is placed and the state would be not flat. then when the state changes to flat then it would fire the procedure to close the other orders in other account or instrument

      Comment


        #4
        Found a problem in the naming of the account, which seems to have cured that object not referenced issue, but still not sure how to accomplish the task of determining the status of when the
        main strategy has no positions then checking for positions in other account

        [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
        public string AccountName { get; set; }​

        Comment


          #5
          Hello set2win,

          Thanks for your note.

          You could look at the account's overall position and not a position for a specific strategy. The accounts have a positions collection to find open positions and this would be the total position for the account.

          It is not suggested to try and link two strategies as you are doing. There would be no way to know if one strategy or another strategy has a position from the positions collection. You would need to create one strategy that opens and closes all positions. Or, you could use indicators and reference the account position directly.

          The code you shared in post # 3 would be what you would need to use to get the overall position of an account.

          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


            #6
            In the end I had an OnExecutionUpdate that I was able to tap into that when the order is exited I could send the ClosePosition to other account.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            51 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            127 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