Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop closing the position too early

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

    SetTrailStop closing the position too early

    Hi there,

    I read several threads on trailing stops and I haven't been able to find the solution the issue below, see if I can get some help from you guys.

    I am backtesting a strategy on daily bars and have setup a trailing stop in the Initialize() method as follows:

    SetTrailStop("Entry1",CalculationMode.Percent,MyPe rcentInput,false);

    The error appears when the range (Hi-Lo) of the entry bar is >= size of the trail stop, but in the direction of the trade. Obviously, it would be right if it was against the position, not in favor.

    If the range of the entry bar is < size of the trailing stop, there is no problem.

    For e.g. the trail stop = 1point, entry short at price = 20, Hi=20.1, Lo=19, Close=19.1.... In this case the price would close 0.9 points in the direction of the trade, moving the initial trailstop from 21 to 20 for the next bar. However the backtesting shows the exit on the same entry bar at the price of entry.

    I don't see any error on the log.

    I've tried playing with the following, with no luck:

    "Calculate on bar close"
    "bool simulated"
    "Entry Handling"
    Copied the SetTrailStop into the OnBarUpdate()

    Any ideas?

    Thanks

    #2
    Miggers,

    Your code is not for 1 point. Your code is for percentages. Going by 1% means 0.20. A low price at 19 would mean you got stopped out.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply Josh,

      I just used those numbers as an easy example, they were not from an actual trade, but these ones below are indeed from one:

      Hi 100.70
      Lo 95.00
      Open 99.20
      Close 96.20

      Entry 99.20 (short), Exit 99.20 (trail stop)

      Trail by 3% (i.e. MyPercentInput = 0.03), this would set the initial stop at the time of entry at 102.18, as the price drops the stop moves down with the price so that at close the stop = 97.85.

      Since at entry the Hi > 97.85 the strategy wrongly exits the trade at entry price. In other trades where the Hi of the entry bar < Stop at close (with the same instrument and same variables) the stop loss works fine.

      Look at the images attached, these come from the actual application of the strategy on the chart.

      Cheers

      Comment


        #4
        I couldn't see the attachments I just posted, I'll try again...
        Attached Files

        Comment


          #5
          Miggers,

          This is expected. Since you only have snapshot OHLC if the initial stop is breached it will consider it as a close.

          You can try using different fill types, but if you do not find one suitable to what you feel should happen you can also custom program your own fill type. Unfortunately doing so is unsupported, but you can find some resources here: http://www.ninjatrader-support.com/H...FillTypes.html
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, Yesterday, 10:06 AM
          0 responses
          22 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          19 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          14 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          10 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          41 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X