Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    116 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    61 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    40 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    43 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    82 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X