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

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.
    Brandon H.NinjaTrader Customer Service

    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.
          Brandon H.NinjaTrader Customer Service

          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 Balage0922, Today, 07:38 AM
            0 responses
            3 views
            0 likes
            Last Post Balage0922  
            Started by JoMoon2024, Today, 06:56 AM
            0 responses
            6 views
            0 likes
            Last Post JoMoon2024  
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            19 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            6 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Working...
            X