Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to exit partially from long position?

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

    How to exit partially from long position?

    Please correct my understanding on partial exit from long/short positions. I have an understanding that we need to use onExecutionUpdate method for this purpose.

    When I use it for exiting 1 contract per line inside the onExecuteUpdate(), as shown below
    HTML Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
                if(longEntryOrder != null && execution.Order == longEntryOrder)
                {
                    ExitLongLimit(CurrentBar, true, 1, FirstTargetLine, "LX1", "BL");
                }​...
    it cancels the exit order and also strategy is automatically disabled. Please help in this regard.
    I want to know how can I partially exit 4 contracts at four different prices?


    Inside the onBarUpdate method I entered into the long position with 5 contract, as shown in the code below
    HTML Code:
    longEntryOrder = EnterLongLimit(5, LongLimitPrice, "BL");

    #2
    scaling out of a position:

    Comment


      #3
      Hello adeelshahzad,

      Thank you for your post and welcome to the NinjaTrader forum community!

      As balltrader mentioned, what you have described sounds like scaling out of a position. We have a reference sample of this behavior specifically at the following link:


      It is not required to use OnExecutionUpdate() to achieve this, however as stated at the link for the SampleOnOrderUpdate() strategy, "The OnExecutionUpdate() method is updated whenever you receive an execution or a fill on your orders. This method provides you the fastest possible submission of protective orders. Utilizing the increased granularity provided in these advanced methods can be advantageous to you by providing you with maximum control of how your stop-loss and profit target orders behave."

      It is up to you whether to use order objects and work with OnExecutionUpdate() or not, though the key to scaling out is to use separate entry methods with unique entrySignal values so that the exits/protective orders may be tied to a portion of the position using fromEntrySignal rather than applying to the entire position.

      Please let us know if we may be of further assistance.

      Comment


        #4
        Thanks NinjaTrader_Emily and balltrader for your help.

        I have gone through the scale out of Position doc. But I have a new confusion now that when should I be using the ExitLongLimit() and ExitLongStopMarket()/ExitLongStopLimit() methods. As per my understanding, these were the methods for scaling out of a position.

        Is it like, that we have multiple methods for applying the scaling out of a position?

        Comment


          #5
          Originally posted by adeelshahzad View Post
          Thanks NinjaTrader_Emily and balltrader for your help.

          I have gone through the scale out of Position doc. But I have a new confusion now that when should I be using the ExitLongLimit() and ExitLongStopMarket()/ExitLongStopLimit() methods. As per my understanding, these were the methods for scaling out of a position.

          Is it like, that we have multiple methods for applying the scaling out of a position?
          You may use any exit methods to scale out of a position. I suspect you are referring to a sample that used Exit() methods as protective orders, so one of the exit orders was intended to be the stop loss and the other was intended to be the profit target. The order methods for the Managed Approach are listed in the help guide here, including the different exit methods that are available:


          Otherwise, in the "Scaling out of a position" reference sample it actually uses the Set() methods for exits:
          Code:
                          /* These Set methods will place Profit Target and Trail Stop orders for our entry orders.
                          Notice how the Profit Target order is only tied to our order named 'Long 1a'. This is the crucial step in achieving the following behavior.
                          If the price never reaches our Profit Target, both long positions will be closed via our Trail Stop.
                          If the price does hit our Profit Target, half of our position will be closed leaving the remainder to be closed by our Trail Stop. */
                          SetProfitTarget("Long 1a", CalculationMode.Ticks, 10);
                          SetTrailStop(CalculationMode.Ticks, 8);
          ​
          For more information on different order types and how they behave:


          Please let us know if we may be of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          41 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 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
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X