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

How to prevent Order Cancellation?

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

    #16
    Hello johnnybegoode,

    You can add a class level bool to the condition. Below would be how you can set that up using a bool called "SubmissionReached" that is initialized as false.

    Code:
    if (!SubmissionReached && YOUR OTHER ENTRY CONDITIONS)
    {
        SubmissionReached = true;
        // Order submission methods here
    }
    The submission will only occur once until the bool is flipped back.

    Then later in OnOrderUpdate when you assign the order, you can set the bool back to false:

    Code:
    if (order.Name == " YourOrderName")
    {
        YourOrderObject = order;
        SubmissionReached = false;
    }
    At this point the order object will no longer be null, so the entry condition will not become true again, but the bool will be reset so the next time the condition becomes true, it only becomes true once.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #17
      Thanks.
      The boolean method works that it stopped exiting continuously
      but it is still submitting too fast.

      Strategy Exits more once and the other exits turned into entry when there should be none.
      (see attachment)

      *** Update:
      I switched SubmissionReached = false
      to after the OrderState.Filled and it
      seems to work for now...

      Code:
        if (entryOrder != null && entryOrder == order)
        {
            Print(order.ToString());
            if (order.OrderState == OrderState.Filled)
            {
                SubmissionReached = false;
                entryOrder = null;
            }
        }
      Attached Files
      Last edited by johnnybegoode; 02-19-2021, 09:44 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      6 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      6 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Working...
      X