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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            47 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            23 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            33 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            50 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Working...
            X