Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot enable Strategy if I do CancelAllOrders(order.Instruments) in State.DataLoaded

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

    Cannot enable Strategy if I do CancelAllOrders(order.Instruments) in State.DataLoaded

    I plan to cancel all existing pending orders when my Strategy starts. The following code will prevent me enabling Strategy (I cannot click to enable the Strategy).

    if (State == State.DataLoaded)
    {
    foreach (Order order in myAccount.Orders)
    {
    myAccount.CancelAllOrders(order.Instrument);
    }
    }


    If I move the above code to under (State == State.SetDefaults), then it works fine. It can cancel all pending orders and start my strategy. But putting under SetDefaults, it is dangerous, because it can be triggered when I start any other Strategies.

    Is there a way to do this under State.DataLoaded and still can enable Strategy?



    #2
    Hello localappleseed,

    Are there errors appearing in the Log tab of the Control Center when trying to enable the strategy?

    If so, what are the errors?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      There is no error, nothing from logs either. Here are the steps to reproduce:
      From NT control -> Strategies -> Right Click to select New Strategies -> Select my Strategy -> When my strategy is shown, from right side there is little square which I should be able to click to enable the Strategy, but I cannot click it, it doesn't respond.

      Comment


        #4
        Hello localappleseed,

        Is the Account selection grayed out or can this be manipulated?

        Is the account connection connected?

        Can you select that account in the Account drop-down of the SuperDOM?

        Has this instance of the script been enabled at least once on a different account?
        If you create a new instance with the correct account selected in the parameters the first time, is the behavior the same?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Click image for larger version  Name:	Pic1.PNG Views:	0 Size:	34.1 KB ID:	1124530

          As you can, the red circled is the place where I tried to enable. It doesn't allow me to enable until I move the code to SetDefaults.
          So answer your question, 1) it it not grayed, cannot be manipulated; 2) yes, connected, because it works fine when I move the code; 3) yes, I can select account of SuperDOM; 4) not tried in different account, but from the same account, I can make it work only moving the 2 lines of code to SetDefaults. 5) the behavior has no difference.

          This is NOT working:

          if (State == State.DataLoaded)
          {
          foreach (Order order in myAccount.Orders)
          {
          myAccount.CancelAllOrders(order.Instrument);
          }
          }

          This is working;

          ​​​​​​​if (State == State.SetDefaults)
          {
          foreach (Order order in myAccount.Orders)
          {
          myAccount.CancelAllOrders(order.Instrument);
          }
          }



          Last edited by localappleseed; 10-25-2020, 07:27 PM.

          Comment


            #6
            Hello localappleseed,

            If the account selection is not being changed on a strategy then I would expect an error in the Log tab of the Control Center.

            So far it's been one or the other and I haven't seen any other reasons that would immediately disable a strategy to date, but I would be extremely interested.

            Are you doing a check for null to make sure the account is not null?
            When and with what code are you getting an account object?

            Print 'myAccount is not null' to the output window in State.DataLoaded from a condition checking for null before the code causing the script to crash without an error message.

            Include the output with your reply.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Everything is the same except I changed one word in the code, see below. Everything including testing procedure, loading data, strategy etc are the same.
              There is no null involved here, as I don't get running error. Nothing printed in logs.
              I am not sure how I answer your question, as I said, only for following line can change the behavior, working or not working. I already narrowed the problem to one line of code. Please help if you can, thanks.


              from
              if (State == State.DataLoaded) // <<<< I cannot enable Strategy
              to
              if (State == State.SetDefaults) //<<<<< I can enable Strategy


              Comment


                #8
                Hello localappleseed,

                May I have a screenshot of the Log tab of Control Center after you have attempted to enable the script so that I may confirm there are no error messages?
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by banhnduurt, Today, 02:18 AM
                0 responses
                3 views
                0 likes
                Last Post banhnduurt  
                Started by ballboy11, 10-04-2020, 02:53 PM
                2 responses
                21 views
                0 likes
                Last Post mav8rick  
                Started by manueldecastro, Today, 01:37 AM
                0 responses
                5 views
                0 likes
                Last Post manueldecastro  
                Started by memonolog, Today, 01:29 AM
                0 responses
                5 views
                0 likes
                Last Post memonolog  
                Started by BennyNewtony, Today, 12:13 AM
                0 responses
                4 views
                0 likes
                Last Post BennyNewtony  
                Working...
                X