Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial Exit Not Working

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

    Partial Exit Not Working

    I can't get the order handling on partial exits to work right. I want to enter at the same time with two positions: one that is linked to both a profit target and a stop loss, and a second that is only linked to a stop loss. I get one total position linked to the profit target, and I get double the size on the stop loss order. What am I doing wrong?

    Here's the code:

    Code:
    #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>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class deleteme : Strategy
        {
            #region Variables
            // Wizard generated variables
            private double target = 8; // Default setting for Target
            private double stop = 8; // Default setting for Stop
            private int qty1 = 4; // Default setting for Qty1
            private int qty2 = 1; // Default setting for Qty2
            // 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()
            {
                SetProfitTarget("order1", CalculationMode.Ticks, Target);
                SetStopLoss("order2", CalculationMode.Ticks, Stop, false);
                SetStopLoss("order1", CalculationMode.Ticks, Stop, false);
    
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if (Close[0] > Close[1])
                {
                    EnterLong(Qty1, "order1");
                    EnterLong(Qty2, "order2");
                }
    
                // Condition set 2
                if (Close[0] < Close[1])
                {
                    EnterShort(Qty1, "order1");
                    EnterShort(Qty2, "order2");
                }
            }
    
            #region Properties
            [Description("")]
            [Category("Parameters")]
            public double Target
            {
                get { return target; }
                set { target = Math.Max(1, value); }
            }
    
            [Description("")]
            [Category("Parameters")]
            public double Stop
            {
                get { return stop; }
                set { stop = Math.Max(1, value); }
            }
    
            [Description("")]
            [Category("Parameters")]
            public int Qty1
            {
                get { return qty1; }
                set { qty1 = Math.Max(0, value); }
            }
    
            [Description("")]
            [Category("Parameters")]
            public int Qty2
            {
                get { return qty2; }
                set { qty2 = Math.Max(0, value); }
            }
            #endregion
        }
    }

    #2
    Prospectus,

    When you are running the strategy at the beginning, please change Stop&Target Handling to PerEntryExecution instead of ByStrategyPosition.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, that was it

      I changed the setting and it works. Thanks for the support!!

      Comment


        #4
        Glad you got it resolved.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 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
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X