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

Cancellation rejected by the Order Management System

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

    Cancellation rejected by the Order Management System

    I have a strategy that can close an order and at the same time send other in the opposite direction, for example, I can be short and I want to close the position at the close of a bar higher than the open but at the same time enter long in that same close, and every time it does It gets an error message "Cancellation rejected by the Order Management System" and what it does is open twice the position in the opposite direction of that new order, in the same example, It can be short with 4 contracts and at the moment when it close the position, It opens a long, but for 8 contracts, but nevertheless it is looks that the first short does not close.
    I understand that I do not violate any Internal Order Handling Rules since I exit the operation with ExitLong () or ExitShort ()
    Could you help me solve how to properly close the original position so on the reverse it does not open the double of contracts?
    Thank you
    This is the code
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1
    || CurrentBars[1] < 0)
    return;

    // Set 1
    if ((Momentum1[0] < 0)
    && (ATRenTicks1[0] >= Rango)
    && (ATRenTicks1[0] < Rango_Max)
    && (Close[1] > Open[1])
    && (Close[0] < Open[0]))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if ((Momentum1[0] > 0)
    && (ATRenTicks1[0] >= Rango)
    && (ATRenTicks1[0] < Rango_Max)
    && (Close[1] < Open[1])
    && (Close[0] > Open[0]))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 3
    if ((Position.MarketPosition == MarketPosition.Short)
    && (CrossAbove(Close, Open, 1)))
    {
    ExitShort(Convert.ToInt32(Position.AveragePrice), "", "");
    }

    // Set 4
    if ((Position.MarketPosition == MarketPosition.Long)
    && (CrossBelow(Close, Open, 1)))
    {
    ExitLong(Convert.ToInt32(Position.AveragePrice), "", "");
    }

    }

    #2
    Hello jeremy8384,

    Thanks for your post.

    I would first suggest using Signal Names so you can more easily identify which orders are affecting how the positions are entered and exited.

    Your logic still may be calling Enter/Exit on the same bar. You can test with the Exit behavior removed to confirm if the Exit behavior is causing the issue.

    I may then suggest adding a bool to the strategy so you can better control the logic.

    Once the bool is created in Inputs and Variables, create a new condition set in Conditions and Actions that does not have any conditions. This should be Condition Set 1. In this Condition Set, create an action that sets the bool to true. This will be done on each bar that the strategy processes, before the rest of the logic is processed.

    In your entry/reversal condition sets, set the bool to false.

    In your Exit condition sets, check if the bool is true before allowing the Exit to take place.

    This will ensure that these methods are not called on the same bar.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      If you still have not found any solution then you might want to try adding additional checks in your code to ensure that the position has been closed before entering into a new one. For example, you could add a check to see if the position is no longer held before entering into a new long or short position. Another alternative you might want to consider is to use a CRM software like Planfix CRM, which can help you with order management, also it can provide you with features like order tracking, order history, and order analytics that can help you better manage your orders.
      Last edited by JosephDavidsona; 01-27-2023, 04:45 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X