Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Positions not closing

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

    Positions not closing

    I am new to NT and am testing a very simple strategy and can not get it to close any positions other than the EOD closeout. The entrys are executing exactly where they should be in the backtest. I just took a Kenetick RT feed subscription so that is the data provider.
    Is there something I am missing?

    Here is the code

    #region Variables
    // Wizard generated variables
    private double stopLoss = 1.5; // Default setting for StopLoss
    private int profitTarget = 3; // Default setting for ProfitTarget
    // 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()
    {
    Add(Stochastics(Close, 0, 14, 3));
    Add(ATR(2));
    Add(Stochastics(7, 0, 3));
    SetStopLoss("long", CalculationMode.Percent, 1.5, false);
    SetTrailStop("long", CalculationMode.Percent, 3, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(Stochastics(Close, 0, 14, 3).K, 18, 1)
    && ATR(2)[0] > 0.02)
    {
    EnterLong(100, "long");
    }

    // Condition set 2
    if (Position.Quantity > 90
    && Stochastics(7, 0, 3).D[2] > 80)
    {
    ExitLong("100", "long");
    }
    }

    #region Properties
    [Description("Stop Loss Pct")]
    [GridCategory("Parameters")]
    public double StopLoss
    {
    get { return stopLoss; }
    set { stopLoss = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int ProfitTarget
    {
    get { return profitTarget; }
    set { profitTarget = Math.Max(2, value); }
    }
    #endregion

    #2
    Hello Plateaulight,

    Thanks for your post and welcome to the forums!

    The percentage values you are using 1.5 and 3.0 are likely too high for the instrument. These values are actually 150% and 300%. For 1.5% use 0.015, for 3% use 0.03.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    68 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X