Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Parital Fill and Stop Order

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

    Parital Fill and Stop Order

    Hi,

    I'm entring a trade and want to make sure my stop loss is updated each time it gets a partial fill.

    I wonder if the correct way to do this is to simply cancel the previous stop order and create a new stop order with an updated quantity as follows (Whenever I get a notification that the entryOrder was udpated, I check if the market position has changed. If so, I cancel the previous stopOrder and issue a new stop order with an updated quantity):

    protected override void OnExecution(IExecution execution)
    {
    if (entryOrder != null && entryOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    if (stopOrder==null)
    {
    // Set ths stop loss for the entryOrder 20 cents cents below stop price
    stopOrder = ExitLongStop(0, true, execution.Order.Filled, entryOrder.StopPrice-20* TickSize, "stop","entry");
    } else if (stopOrder.Quantity!=Position.Quantity)
    {
    // Need to update the stop order with the correct quantity
    CancelOrder(stopOrder);
    stopOrder = ExitLongStop(0, true, execution.Order.Filled, entryOrder.StopPrice+20* TickSize, "stop" , "entry");
    }
    }
    }
    }

    I'd appreciate if you could let me know if that's the right approach.

    Regards,

    Ron

    #2
    Hello,

    Thanks for the forum post.

    I would recommend using this instead.



    This way you do not have a time where you do not have a stop. Even if its milliseconds.

    -Brett
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi Brett,

      ChangeOrder is an unmanaged approach command.
      My strategy uses managed apparoch commands.
      Can I use CahangeOrder in that case? (I thought that we can't mix commands from different approaches).

      If not, is there an alternative using the managed apparoch ?
      Ran

      Comment


        #4
        Hello,

        Ah yes you are correct, I only saw the first half of your code segment and saw some of the unmanaged code side therefor I assumed incorrectly you were using unmanaged approach. Sorry about that.

        With the managed approach with ExitLongStop this would be the best way to do this and is the case if you needed to use ExitLongStop().

        However there is even a better way which is the SetStopLoss() command. Is there a specific reason why you need to use ExitLongStop vs SetStopLoss(). With SetStopLoss() this will do all this for you automatically and no need for extra coding. Furthermore, you can modify the price of SetStopLoss() with this sample.

        BrettNinjaTrader Product Management

        Comment


          #5
          Hi Brett,

          The reason why I have to use the ExitLongStop() command (and not SetStopLoss) is this:

          1. I write a strategy and enters a trade and keeps a stop loss. I scale out from the trade in a few places.
          2. I enter the trade using the EnterLongStopLimit() command.
          3. When scaling out, I want to make sure my stoploss quantity is updated (I also move my stoploss price).
          4. Since my broker charge me different commissions on different quanitites. I want to make sure I have only ONE stoploss (instead of multiple stoplosses command per the same price).


          Per my understanding, the only way I can satisfy the above requirements is to manage the stoploss price within my strategy and exit the trade using the ExitLongStop() when the stoploss price is hit.

          I'd appreciate if you could let me know if you have any other suggestions.

          Ron
          Last edited by rmaron; 01-09-2012, 04:27 PM.

          Comment


            #6
            Hello,

            Unfortunately I regret to inform you that this type of setup would not work.

            The reason why is with the managed approach an internal handling order rule found here that says the following:



            Methods that generate orders to exit a position will be ignored if:
            A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
            A position is open and an order submitted by a set method (SetStopLoss() for example) is active

            Therefor the system will automatically ignore your ExitLongStop() since you have a stop already in the market. The reason why it is doing this is it doesnt want both stops to get hit and leave you with an unexpected position.

            To do what you need to do unfortunately you would need to switch over to the unmanaged approach unfortunately since you require greater management of your orders then the managed side can provide.



            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment


              #7
              Hi Brett,

              Regarding your comment. In order not to have multiple stops I cancel a stoploss command before entering a new stoploss command.
              For exmaple:
              Suppose I sent a stoploss order (using the ExitLongStop() command and I want to move the stoploss to another level.
              Then before calling ExitLongStop() command I call the CancelOrder(stopOrder);

              This way, I make sure there are no two stoploss set.
              I think this should work. What do you think?

              Regards,

              Ron

              Comment


                #8
                Ron,

                Yes this is what you will need to do to make this work.

                -Brett
                BrettNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                574 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X