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

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, 08: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 Christopher_R, Today, 12:29 AM
                0 responses
                4 views
                0 likes
                Last Post Christopher_R  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,234 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                1 view
                0 likes
                Last Post thread
                by thread
                 
                Started by jclose, Yesterday, 09:37 PM
                0 responses
                7 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,414 views
                0 likes
                Last Post Traderontheroad  
                Working...
                X