Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why are stoplosses so buggy?

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

    Why are stoplosses so buggy?

    I've been having some problems with stop losses not getting triggered, I've also tried exiting trades when certain conditions are met, even though I have checked the logic over and over there shouldn't be any reason for this not working.

    I've read people have had problems for years to do with buggy stop losses so why has this not been fixed yet?

    #2
    Welcome to the forums bensharpe!

    There have been cases where profit targets and stop losses are not submitted because best practices are not followed to call SetProfitTarget/SetStopLoss when the strategy is flat, before the next entry is submitted. You may see our example below for the advised way to use these methods if they are used dynamically in OnBarUpdate.

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    There are also cases where custom profit targets and stop losses are not submitted due to logical issues in the strategy.

    Each case may be unique.

    If you are experiencing an issue and have confirmed that you are following best practices, please remove the entry logic from your strategy so it enters positions without the need for the entry logic to become true to enter a position, and so we can see how you are submitting profit targets and stop losses in a simplistic fashion. Please also test using the Playback connection to see if the issue can be reproduced there.

    With an exported test script and steps to reproduce, we can give further insight for an issue with how the targets/stops are submitted in the strategy, or look into a deeper issue if that is the case.

    Playback - https://ninjatrader.com/support/help...connection.htm

    Exporting as source code - https://ninjatrader.com/support/help...tAsSourceFiles

    We look forward to assisting.

    Comment


      #3
      Thanks for the response. Could you point me to some code examples of good practices as I can't really find any.

      This is the basic logic for entering and exiting trades, when a condition is met I place the stop loss which is always the same number of pips, then enter a trade. I've never had a problem entering a trade, but the stop losses don't get triggered. I'm 100% certain that the logic for exiting is correct although some trades still aren't closed when they're supposed to. All the logic is inside OnBarUpdate and calculated OnBarClose. I'd appreciate it if you could show me where it's going wrong

      if (longEntry)
      {
      SetStopLoss(CalculationMode.Pips, 10d);
      EnterLong();
      }
      else if (shortEntry)
      {
      SetStopLoss(CalculationMode.Pips, 10d);
      EnterShort();
      }

      if (longExit)
      {
      ExitLong();
      }
      else if (shortExit)
      {
      ExitShort();
      }

      Comment


        #4
        Hello bensharpe,

        SamplePriceModification from my last reply will demonstrate best practices for using the Set methods in OnBarUpdate.

        General best practices can be found here - https://ninjatrader.com/support/help..._practices.htm

        The logic that you have would be valid for submitting stops and targets. Instead of checking if (longEntry) and to simply check if (Position.MarketPosition == MarketPosition.Flat), we would be left with a script that simply enters and demonstrates the target/stop submission. If you can reproduce the symptoms in Playback or with the Sim101 account with that test script, please send us the test script and detail how we would reproduce the issue.

        We would need an export of the test script since the properties used in the strategy will also be relevant for the case.

        If the issue is seen specifically with partial fills, you can force partial fills from the Control Center's Tools > Options > Trading menu.

        If the issue is not seen with Sim101 or Playback, we should then focus trading on a paper trading account to then look into anything specific for that connection type.

        Please keep us informed on these tests and if we have a test case that we can reproduce, we will be happy to analyze on our end.

        Comment


          #5
          I've just been messing around with the code, I'm not sure what I changed but everything is working perfectly now. Just need to make that little change you recommended checking if the market position is flat. Thanks for your help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          133 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X