Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit order is overridden by a new exit order

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

    Exit order is overridden by a new exit order

    Hey there,

    So, this may be a feature and expected (ChangePending order state).

    Heres the scenario:
    1. Enter a long trade with 100 contracts
    2. Price in profit
    3. Call ExitLong(70)
    4. Straight after without waiting for the exit order to fill, call ExitLong(30).
    5. The first ExitLong(70) will be cancelled and only the ExitLong(30) will be filled.

    Therefore the existing order is overridden if it is in a working state and a new one is submitted.

    Simple test I wrote is:

    Code:
    bool canExit = true;
    
    protected override void OnBarUpdate ()
    {
    if (Time[0].Day == 24 && Time[0].Hour == 14 && Time[0].Minute == 45)
    {
    if(Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLong(100);
    }
    }
    
    if (canExit == true&& Time[0].Day == 24 && Time[0].Hour == 15 && Time[0].Minute == 00)
    {
    ExitLong(30);
    ExitLong(70);
    canExit= false;
    }
    }
    I tried to run each ExitLong on a new thread but that didn't seem to work however, I only briefly tried and there may be another reason that didnt work.

    I believe, by looking at the order traces, the second ExitLong puts the order state into: ChangePending?.

    Is there any way to fulfil the first order and the subsequent orders and never cancel/ change?

    Thanks,

    Tarik

    #2
    Hello tarikmedjber,

    If the goal is to exit the whole position you don't need to call ExitLong twice, you would just need to call it once with either no quantity specified or the full quantity specified.

    When you scale out of a position it is best to use signal names and multiple entries so each exit is associated with a specific part of a position by using that entries signal name. Calling exit long twice for the same position before any position update happens could cause unexpected results. There is a sample of scaling out here: https://ninjatrader.com/support/help...a_position.htm



    Comment


      #3
      Hmmm yeah, so, it’s not always the full position I close out of. That was just an example. And then, for the reason I do two instead of just one exit long is because I have several different classes that hold logic on whether to exit a trade or not and sometimes they want to exit at the same time (but maybe like, a few milli seconds a part obviously).

      if you have no other suggestions, maybe I can just have a temporary holder of exits and I accumulate them until all the code is ran and then I exit whatever was accumulated.

      but the above is risky because I obviously want to exit ASAP

      Comment


        #4
        Actually, if I can check if there’s an order currently in progress, I can potentially cancel it and re enter the order with the extra contracts?

        Comment


          #5
          Hello tarikmedjber,

          Yes you would need to go with your temporary holder idea, calling multiple entry or exit methods at the same time will result in unexpected results, you need at least 1 OnBarUpdate call between those events so each order is submitted individually.

          If the quantity you scale out is variable then you would need to use extra logic to determine how much to exit however that can still lead to unexpected situations. It would be suggested to use the unmanaged approach if you want to specify odd quantities to scale out that would not match a specific entry. That would avoid any of the internal order handling rules or signal name system that are used in the managed approach order methods, that instead just submits the orders as you specify individually and then you would be in control of that order over its lifetime.

          Comment


            #6
            Sorry I got a bit lost on the last part after suggesting the unmanaged approach.

            Comment


              #7
              Hello tarikmedjber,

              You can read about the different approaches for order submission that NinjaTrader provides here:

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              20 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              119 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              63 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              41 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              45 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X