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.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sgordet, Today, 11:03 AM
    0 responses
    6 views
    0 likes
    Last Post sgordet
    by sgordet
     
    Started by trimpy, 03-11-2025, 10:21 AM
    7 responses
    41 views
    0 likes
    Last Post rockmanx00  
    Started by gbourque, Today, 08:52 AM
    0 responses
    18 views
    0 likes
    Last Post gbourque  
    Started by davydhnz, Today, 08:04 AM
    0 responses
    13 views
    0 likes
    Last Post davydhnz  
    Started by michelz, 02-18-2025, 08:30 AM
    18 responses
    408 views
    0 likes
    Last Post neveral0n3  
    Working...
    X