Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using SetStopLoss() and SetTrailStop() in a strategy

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

    Using SetStopLoss() and SetTrailStop() in a strategy

    I am looking into using a combination of these to functions SetStopLoss() and SetTrailStop(). As mentioned in the documentation SetStopLoss() will take priority over SetTrailStop(). This seems to present an bit of a race condition on all trades following the first trade. The issue as these levels are not truly 'reset' once a trade is closed as the previous levels of a Set*Stop will carry over to new trades and these must be set before every trade because levels are not entirely removed.

    I have functions that handle updating the SetTrailStop because of the previously mentioned need to 'reset' but I only wish to start using the SetStopLoss() under conditions where I need a finer control of the stop threshold I am otherwise happy to rely on SetTrailStop.

    My question, is there a way to handle these two functions together such that setTrailstop will be used in all trades unless I register for a specific trade the need to use setstoploss()?

    #2
    Hello Cornhusk7789,

    There is no way to use those methods together. You would need to use one or the other. If you need more specific control over the trailing you can just use SetStopLoss, each time you call that method it will update the existing stop to the new offset you specify.

    Comment


      #3
      Thank you for the quick response.

      I haven't found specifics on this yet scrolling through related search results to SetStopLoss. But assumption of the SetStopLoss() function is it will set the stop loss when using tick mode to be relative to the average entry point and not of the current price. So if I wanted to start trailing above the entry point to maintain a positive PnL and avoid reversal losses. Would I need to transition to using the Price mode? Can this be altered while still in a position or do I have to maintain the mode as well?

      Or alternatively is there a better approach to tightening the trailing stop loss such that it allows less movement in price. Because I like the trailing stop but I want to really close the gap size from current price to stoploss to essentially reduces losses or improve pnl outcomes if the trade entry was at some point positive and capture those gains, before it reverses entirely.

      A couple examples of what I'm referring to.

      Click image for larger version

Name:	image.png
Views:	121
Size:	16.4 KB
ID:	1313011 zz0.oqolza42jakzz
      Last edited by Cornhusk7789; 08-05-2024, 12:34 PM.

      Comment


        #4
        Hello Cornhusk7789,

        If you want to use specific prices you need to use the CalculationMode.Price, that lets you specify a calculated price. You can use that the same as any of the other modes, when you initially call the method it places a stop. If you later want to change the order you call the method again with new values for the offset or a new price when using CalculationMode.Price. You can change the mode if you wanted to at a later time.

        Regarding less movement, the SetTrailStop is amended based on the Calculate setting of the script, to have it move more frequently at smaller amounts would require using OnEachTick or OnPriceChange in realtime. If you are using OnBarClose the trailing will happen on each bar close which could lead to larger price movements between trails.





        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        113 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        60 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
        81 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X