• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SL and TP targets do not exeucte when reversing your trade - Managed Approach

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

    SL and TP targets do not exeucte when reversing your trade - Managed Approach

    Reversing a position with static SL and TP using SetProfitTarget(CalculationMode.Ticks,profitTarget Ticks) & SetStopLoss(CalculationMode.Ticks, stopLossTicks) works fine.

    The problem lies when you use non static SL and TP assigned on OnExecutionUpdate to a price value.

    If you have an open position either long or short and assigned a stop loss or take profit orders to that position, if you reverse that position with an EnterShort() or EnterLong(). The strategy does not submit SL and TP orders for the new reverse position that you are in even though through print statements you can see that it follows the same flow as if it was like any other entry from Flat.

    #2
    Hello cutzpr,

    Thanks for your post.

    Set methods are designed to be submitted before the entry order is submitted. They prep NinjaTrader to submit targets and stops at those levels when the entry order comes back as filled. As described in our Modifying Stops and Targets example, these should be reset to an initial value when the strategy is flat and before the strategy submits an entry for a new position.

    In the case of reversing, we could specify initial levels before we reverse. Keep in mind this will also modify the active stops before the reversal occurs. For example, in OnBarUpdate:

    Code:
    // Reverse
    if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntryExecution() == 2)
    {
        SetStopLoss(CalculationMode.Ticks, StopLossTicks *2);
        SetProfitTarget(CalculationMode.Ticks, ProfitTargetTicks*2);
        EnterShort();
    }
    f you would like to simply place orders for target and stop on the execution of an entry order using OnExecutionUpdate, I would recommend using Exit orders instead of using Set methods. The SampleOnOrderUpdate strategy can be used as an example for how this is done.

    The examples I mentioned can be found below.

    SamplePriceModification - https://ninjatrader.com/support/help...s_superdom.htm

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      The SetStopLoss and SetProfitTarget work perfectly. The issue is when not using these methods. I am using exit methods for the SL and TP within OnExecutionUpdate. If a new entry order is placed when the strategy is flat then there is no problem. The strategy places the corresponding SL and TP. But if you reverse the position, (you are long and execute EnterShort() for example) it does not put in the SL and TP orders for the corresponding short. As I stated, the problem lies when you use non static SL and TP assigned on OnExecutionUpdate to a price value.

      Comment


        #4
        Hello cutzpr,

        I have attached an example that follows the SampleOnOrderUpdate approach and demonstrates how you can reverse your position with it.

        Please let me know if you have any additional questions.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Jim,

          Thank you very much. Sorry for the late response. The sample you provided was a great help. It was an issue with SL and TP orders not being nullified when they needed to be.

          Comment


            #6
            I have a follow up question with the sample you provided. In the code you are modifying the stop order using the following code
            Code:
            stopOrderLong = ExitLongStopMarket(0, true, stopOrderLong.Quantity, Position.AveragePrice, "MyStop", "MyEntryLong");
            instead of

            Code:
            ChangeOrder(stopOrderLong,stopOrderLong,Quantity,0,Position.AveragePrice);
            is there a difference in how these modifications of the order are handled? Which method would be preferred?

            Also I noticed that you are not canceling any orders. So when you override the order variable
            Code:
            stopOrderLong
            that automatically canceled the order that it refereed to?

            Comment


              #7
              Hello cutzpr,

              You would be free to modify an order using ChangeOrder or calling the order method again with the same signal names to modify the existing order. Assigning the order method's return value to an Order object updates that Order object.

              Orders are cancelled automatically when the position is reversed as a part of the Managed Approach's built in functionality.

              Please let me know if you have any additional questions.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by nikolaalx, Today, 07:31 AM
              1 response
              8 views
              0 likes
              Last Post bltdavid  
              Started by HiddenPhilosopher, Today, 09:28 AM
              0 responses
              2 views
              0 likes
              Last Post HiddenPhilosopher  
              Started by tipslark, Today, 07:23 AM
              0 responses
              12 views
              0 likes
              Last Post tipslark  
              Started by Grantx, Today, 06:49 AM
              0 responses
              9 views
              0 likes
              Last Post Grantx
              by Grantx
               
              Started by muhuzekob, Today, 05:59 AM
              0 responses
              7 views
              0 likes
              Last Post muhuzekob  
              Working...
              X