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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    132 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X