Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing Stop Thru Wizard Not Working

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

    Trailing Stop Thru Wizard Not Working

    I always use the wizard to develop my strategies as much as possible before manually making changes. However, I have NEVER been able to get the SetTrailStop to work. It will never increment the trailing stop value. Instead, it will close out the position when a new condition is true. I have and example of the code below. What do I need to do to get the Trailing Stop to increment???

    See posted chart for additional info.

    Thanks for any assistance!!!

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// N/A
    /// </summary>
    [Description("N/A")]
    public class ForumExampleHMA : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int trailStop = 10; // Default setting for TrailStop
    private int stopLoss = 15; // Default setting for StopLoss
    private int jMAperiod = 15; // Default setting for JMAperiod
    // 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()
    {
    SetStopLoss("LONG", CalculationMode.Ticks, StopLoss, false);
    SetStopLoss("SHORT", CalculationMode.Ticks, StopLoss, false);
    SetTrailStop("LONG", CalculationMode.Ticks, TrailStop, false);
    SetTrailStop("SHORT", CalculationMode.Ticks, TrailStop, false);
    CalculateOnBarClose = true;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Rising(JMA(10, 0)) == true
    && JMA(10, 0)[1] < JMA(10, 0)[2])
    {
    DrawDot("My dot" + CurrentBar, false, 0, Low[0] + -4 * TickSize, Color.Cyan);
    EnterLong(DefaultQuantity, "LONG");
    }
    // Condition set 2
    if (Falling(JMA(10, 0)) == true
    && JMA(10, 0)[1] > JMA(10, 0)[2])
    {
    DrawDot("My dot" + CurrentBar, false, 0, High[0] + 4 * TickSize, Color.DarkOrange);
    EnterShort(DefaultQuantity, "SHORT");
    }
    }
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int TrailStop
    {
    get { return trailStop; }
    set { trailStop = Math.Max(0, value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public int StopLoss
    {
    get { return stopLoss; }
    set { stopLoss = Math.Max(1, value); }
    }
    [Description("Default for all charts")]
    [GridCategory("Parameters")]
    public int JMAperiod
    {
    get { return jMAperiod; }
    set { jMAperiod = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #endregion
    Attached Files

    #2
    dewurster,

    SetStopLoss() overrides SetTrailStop(). I would suggest using the following reference sample to manage stops.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Yes, I can see that stop loss overrides a trail stop. However, trail stop does not seem to be working like I would think it does. For example if I trading oil (CL) and using a 15 tick trail stop, I go long at 107.14 and the trail stop hits at 107.05 for a loss. It doesn't make sence to me. In another example, I go short at 107.15 and the trailstop closes me out at 107.05 for a win. I don't undersand the trailstop's behaviour. Can you please explain with examples how the trailstop works? Thanks!

      Comment


        #4
        dewurster,

        Did this happen in backtesting or on a live connection trading to a simulated account?
        Adam P.NinjaTrader Customer Service

        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