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

When to set Stop/Profit targets?

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

    When to set Stop/Profit targets?


    When is the preferred section of code to call SetStopLoss/SetProfitTarget?

    1) I've seen older sample code which sets the stop loss/profit target within the (State == State.Configure) section
    2) Then, in new sample code, it seems like the stop loss/profit target are being set within the OnExecutionUpdate() section
    3) In other code, I've seen the stop loss/profit target call in the OnBarUpdate() section, either before or after the EnterShort()/EnterLong() is called.

    Out of these three possibilities, is any one of them preferred? Or, is it pretty much three different ways of accomplishing the same task?

    Thanks,





    #2
    Hello timmbbo,

    Thank you for your post.

    Ultimately, it depends on your needs and your preferences. If you are using a static offset, such as simply a number of ticks or percentage away from the entry price, you could call SetStopLoss() and SetProfitTarget() in State.Configure.

    If you want dynamic stops/targets, such as set to a specific price based on a variable or stops/targets that move (like a breakeven, trail stop, or profit chase) then you would need to call them dynamically such as OnBarUpdate() or OnExecutionUpdate().

    As noted in the help guide:
    • It is suggested to call this method from within the strategy OnStateChange() method if your stop loss/profit target price/offset is static
    • You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss/profit target 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/profit target price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss/profit target order on your next open position
    Here are the help guide pages for SetStopLoss() and SetProfitTarget() for more details:​Here is an example of a strategy that modifies the price of stop loss and profit target orders:


    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 fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,406 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X