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

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 Skifree, Today, 03:41 AM
              5 responses
              13 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Started by Mongo, Today, 11:05 AM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by traderqz, Today, 12:06 AM
              6 responses
              13 views
              0 likes
              Last Post traderqz  
              Started by traderqz, Yesterday, 09:06 AM
              5 responses
              34 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by guillembm, Today, 11:25 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X