Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

To get the number of running strategies for all accounts.

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

    To get the number of running strategies for all accounts.

    Hi.
    task: to get the number of running strategies for all accounts.
    used:

    Code:
    else if (State == [B]State.Terminated[/B])
    {
                    Account.Strategies.Select(s => s.Account.Name).ToList().ForEach(Print);
                                                //attempt to print the names of all accounts of existing strategies.
                                                // always prints the name of the[B] current account[/B].
                   var strategyCount = Account.Strategies.Where(s => !s.IsTerminal).Count();
                                                // attempt to get the number of not completed strategies
                                                // always prints the number of
                                                // not completed strategies for the[B] current account[/B].
    }
    question:
    How to get the number of running strategies for all accounts when any strategy is disabled?

    #2
    Hello Danila,

    What is not working in this code?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      I expect to see ALL account names for ALL strategies that are in my system.
      for example :
      1. I have two accounts Sim101 and Sim102
      2. THREE identical strategies are launched (strategy names are the same): Pic 1
      B1(Sim101)
      B1(Sim102)
      B1(Sim102)
      Click image for larger version  Name:	Q9_1.png Views:	0 Size:	7.8 KB ID:	1214353
      3. turn off B1 (Sim102)
      4. when disconnecting B1(Sim102) (in the block if state == terminated)
      I request an array of strategies and for each strategy, I call the account name.
      since there are three strategies in the system, I expect to see the printing of three accounts' names: Sim101, Sim102, Sim102.
      but I get only two: Sim102 and Sim102. Pic 2
      Click image for larger version  Name:	Q9_2.png Views:	0 Size:	12.9 KB ID:	1214354

      between the first parenthesis of the beginning of the "if" check block, there is no code.
      The block starts with printing all the accounts names that the strategies have.
      But it prints the names of the current account, the one that is called this code.
      but I expect to see ALL account names for ALL strategies that are in the system: Sim101, Sim102, Sim102.

      ps.
      this is a simplified task. in fact, I need to get the number of working(enabled) strategies for all accounts.
      but I'm limited in this code to the current account only.
      Last edited by Danila; 09-04-2022, 11:24 PM.

      Comment


        #4
        Hello Danila,

        Your code does not get strategies for all accounts, as you are using the Account of the current strategy and listing the .Strategies of that one account.

        If you want all accounts use the Account.All collection.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB.
          Thanks for your answer.
          It helped me to complete the task.

          Comment


            #6
            Originally posted by Danila View Post
            Hello ChelseaB.
            Thanks for your answer.
            It helped me to complete the task.
            Hi Danila,

            I'm looking to do something simular. Would you be okay sharing the final result? I have trouble re-producing it on myself.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            63 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            139 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X