Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I programmatically reject an order based on contract volume?

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

    Can I programmatically reject an order based on contract volume?

    Hello,

    I'm exploring advanced order handling capabilities. Specifically, I am interested in adding a feature to my addon tool that programmatically rejects orders based on certain criteria.

    The scenario I want to address is the following: If an order is submitted with a contract volume that exceeds a predefined threshold, the order should be automatically rejected before execution. For example, if the threshold is set to 100 contracts, any order request to buy or sell more than 100 contracts should be rejected by the code when its in the Submitted state.

    Could you please guide me on whether this functionality can be implemented in NinjaTrader? If yes, I would appreciate any pointers on which classes or methods I should use to customize this order rejection criteria. Also, is there any sample code available that demonstrates similar custom order rules?

    Thank you in advance for your assistance!

    Best regards,

    Aviram Y
    Aviram Y
    NinjaTrader Ecosystem Vendor - Aviram Y

    #2
    Hello Aviram Y,

    If the addon is submitting the orders with <Account>.Submit(), you can use logic to decide if the order will be submitted or not.

    Is the addon submitting the orders?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB, thanks for the reply..

      No, in this particular case i submit the order via an open order on the chart itself, see attached image for reference.
      currently this is the only specific case where i can't prevent order submission for my tool via UI based event handlers because i could not find a way to attach the specific handler to the order type.

      so i turned to direct order management by subscribing to an OnOrderUpdate for each account and then determining based on a custom criteria if the order is viable or not for entry, in my case when the order is in the submitted i go through all the orders belonging to that account and cancel the order completely, but im afraid that this wont work if there's a delay or the order state is changing in an asynchronous manner somehow and my code updates it too late, causing an unwanted entry with a set amount of contracts.
      this is the code i use currently:
      Code:
      public void OnOrderUpdate(object sender, OrderEventArgs e, Account account)
      {
      // Example of checking order constraints before allowing modifications
      if (e.Order.OrderState == OrderState.Submitted)
      {
      
      ManageOrders(account);
      
      }
      else if (e.Order.OrderState == OrderState.Filled)
      {
      // Handle other states like filled orders
      Print($"Order filled with quantity {e.Order.Quantity}.");
      }
      }​
      and the relevant code from the ManageOrders method:
      Code:
      List<Order> ordersToCancel = new List<Order> { newestOrder };
      account.Cancel(ordersToCancel);​
      Attached Files
      Aviram Y
      NinjaTrader Ecosystem Vendor - Aviram Y

      Comment


        #4
        Hello Aviram Y,

        Attempting to interfere with a manually submitted order is not supported by NinjaTrader as this would inhibit the intended functionality.
        Unfortunately, I would not be able to assist with this.
        This thread will remain open for any community members that would like to provide unsupported code.

        The suggested direction would be to use the addon approach to submit or not submit the orders. The addon (or indicator using the addon approach) could add buttons to the chart to allow the user to invoke the addon to submit the order.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        581 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        338 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X