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 zstheorist, Today, 07:52 PM
    0 responses
    6 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    6 views
    0 likes
    Last Post tkaboris  
    Working...
    X