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

Using SetStopLoss()

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

    Using SetStopLoss()

    Hi, I have some questions about this method please. I have read the online guide for SetStopLoss, SetProfitTarget, ExitLongStopMarket, OnOrderUpdate and OnExecutionUpdate and I believe I want to start using the SetStopLimit() and SetProfitTarget() methods. But if I need to use others to achieve my objectives please let me know.

    I want to be able to set a stoploss and profit target with OCO for any entry order that is triggered so I am looking at the SetStopLoss() and SetProfitTarget() methods. I then want to move that stoploss up to breakeven after a certain profit. I will be trading stocks through IB so it is imperative that the stoploss is placed immediately on a partial fill and updated as more partial fills occur. I believe IB forces you to use StopTargetHandling of ByPositionStrategy.

    My questions
    1. If I use SetStopLoss() method and StopTargetHandling ByStrategyPosition, will each partial fill result in a single stoploss order immediately that proportionately protects the partial position and is updated as additional fills occur? or does it wait until the whole position is filled to place the stoploss? If it does handle partial fills is the stop moved to cater for increasing quantity and the change in average price as more partial fills occur? I want to ensure that the strategy protects positions like the example at the bottom of the OnExecutionUpdate() page (https://ninjatrader.com/support/help...tionupdate.htm) which monitors and manages partial fills using and the ExitLongStopMarket() method. But I want to use SetStopLoss for it's OCO capabilities. If I have to use ExitLongStopMarket() instead please advise.

    2. How do i access the StopLoss associated with the Order object for the execution to check the stoploss has been placed at the correct level (Av Price - some quantity of ticks). I want just to use Print() to output it so I can check it's placed correctly.

    3. The SetStopLoss() method doesn't seem to return its own order object like ExitLongStopMarket(), How do I update the StopLoss associated with the execution order so I can move it to breakeven at some point in the future?

    I am not an experienced programmer, could you please address each question individually for me.

    Thankyou

    #2
    Hello sjmuk1,

    Thanks for your post.

    Using StopTargetHandling.ByStrategyPosition means that Stop and Target order quantities will match the current strategy position. (Stops and targets may result in "stacked" orders on partial fills). If you would prefer all of your stops and targets to be placed at the same time within the same order, it is suggested to use StopTargetHandling.ByStrategyPosition. However this may result in more stop and target orders being submitted than the overall strategy position in a scenario in which the strategy's entire entry orders are not filled in one fill.

    In cases where the strategy's entry order is partially filled, using StopTargetHandling.PerEntryExecution will result in a new set of stop loss and profit target orders for each entry execution.

    StopTargetHandling: https://ninjatrader.com/support/help...ethandling.htm

    Set methods are typically used to prep NinjaTrader to place a protective order when an entry order is filled. You may call this method from only within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position as mentioned on the SetStopLoss() help guide page.

    SetStopLoss(): https://ninjatrader.com/support/help...oss.htm​

    If you will be working with a stop loss in your script and want to use OnOrderUpdate() and OnExecutionUpdate(), Exit methods should be used so that you can track each order object in your script.

    We have example scripts demonstrating using Exit methods and moving a stop to breakeven or creating a trailing stop on the forum thread linked below.
    https://ninjatrader.com/support/foru...der#post806596

    You could find a reference sample demonstrating using OnOrderUpdate() and OnExecutionUpdate() on this help guide page.
    https://ninjatrader.com/support/help...and_onexec.htm

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply but it isn't really answering the questions I asked.

      The Guide page for StopTargetHandling specifically says that with IB you have to use ByStrategyPosition. So I cannot use PerEntryExecution.

      Can you please read my questions again and answer the following?

      1. If I use SetStopLoss with ByStrategyPosition how are partial fills handled? Is the order set for partial fills and updated as additional fills occur or is it just placed at the end of the fill? Please give a simple response.

      2. Please explain this more simply "If you will be working with a stop loss in your script and want to use OnOrderUpdate() and OnExecutionUpdate(), Exit methods should be used so that you can track each order object in your script.". What exactly are you saying in relation to SetStopLoss(), What do you mean by an Exit methods?

      3. If I use SetStopLoss() can this be checked or updated after it is set? Yes or No Please, if Yes please explain.

      4. Given what I am trying to achieve please guide me as to whether I should use SetStopLoss() and SetProfitTarget() or not.

      Please answer each point individually this time.

      Comment


        #4
        Can I get a response please?

        Comment


          #5
          Hello sjmuk1,

          Thanks for your patience.

          In the Engineering Support department, we respond to tickets/forum posts in the order that they are received.

          1. When SetStopLoss() is used with StopTargetHandling.ByStrategyPosition, all of your stops and targets are placed at the same time within the same order. See the demonstration video linked below.



          In the demonstration video above, we see that we have two partial fills occur that equal up to our total order quantity. One partial fill is for a quantity of 990 and the second partial fill is for a quantity of 10 to total a quantity of 1000. The orders are then "stacked" together and show a total entry quantity of 1000 on the order marker. We also see another crossover occur and there are two partial fills that "stack" together again as well.

          2. As stated in the help guide page, Set methods, such as SetStopLoss(), should only be called in OnBarUpdate() if you want to dynamically change them. This means Set methods should not be used in OnOrderUpdate()/OnExecutionUpdate().

          See this help guide page noting this for SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm

          To track order objects and use OnOrderUpdate()/OnExecutionUpdate() you must use Exit methods, such as ExitLongStopMarket() or ExitLongLimit(), instead of Set methods. The reference sample linked in post # 2 demonstrates how OnOrderUpdate()/OnExecutionUpdate() could be used.

          3. Yes, as stated in the SetStopLoss() help guide page linked above:

          "You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position

          Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position"


          This reference sample demonstrates modifying the price of Set methods in OnBarUpdate(): https://ninjatrader.com/support/help..._lo.htm​

          4. You should use Exit methods, not Set methods, if you want to use OnOrderUpdate() and OnExecutionUpdate(). Otherwise, you could use Set methods and dynamically change them in OnBarUpdate.

          Let me know if I may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X