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

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.
      Emily C.NinjaTrader Customer Service

      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.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lightsun47, Today, 03:51 PM
          0 responses
          5 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          12 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          46 views
          0 likes
          Last Post futtrader  
          Started by Option Whisperer, Today, 09:55 AM
          1 response
          14 views
          0 likes
          Last Post bltdavid  
          Started by port119, Today, 02:43 PM
          0 responses
          10 views
          0 likes
          Last Post port119
          by port119
           
          Working...
          X