Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why are my trailing stop losses not triggering?

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

    Why are my trailing stop losses not triggering?

    I'm running strategy analyzer, I used the wizard to develop the strategy and the trailing stop loss never triggers a sell. Here is the code:

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class donchian : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int donchianleveltop = 40; // Default setting for Donchianleveltop
    private int donchianlevelbottom = 10; // Default setting for Donchianlevelbottom
    private int stoploss = 10; // Default setting for Stoploss
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetTrailStop("", CalculationMode.Percent, Stoploss, true);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (High[0] >= DonchianChannel(Donchianleveltop).Upper[0])
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (Low[0] <= DonchianChannel(Donchianlevelbottom).Lower[0])
    {
    ExitLong("", "");
    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int Donchianleveltop
    {
    get { return donchianleveltop; }
    set { donchianleveltop = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Donchianlevelbottom
    {
    get { return donchianlevelbottom; }
    set { donchianlevelbottom = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Stoploss
    {
    get { return stoploss; }
    set { stoploss = Math.Max(1, value); }
    }
    #endregion

    #2
    oyz79, your stopLoss input value is too high, for a TrailingStop of 1 percent, please enter 0.01 for example and then recheck.

    Thanks

    Comment


      #3
      Sorry, I should have put this in my first post - when I entered 0.01 for my stop loss while doing a strategy analyzer I get a message "Property Value is not Valid"

      Comment


        #4
        Yes, as you setup your stopLoss user input as Integer value, try a double here instead -

        Code:
        private double stoploss = 0.01; // Default setting for Stoploss

        Comment


          #5
          Great, thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          574 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X