Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Order Handling

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

    Problem with Order Handling

    Dear NT Support,

    I have a simple test strategy which defines three limit levels with a profit target for each level. To my understanding the maxumum number of contracts this strategy should buy at once is 6 (1+2+3), but somehow nine contracts get bought. In this particular case that happens after the limit L3 gets executed twice at 14:01:09 and 14:05:06.

    The settings for the Order Handling are:

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    What am I doing wrong?

    Thank you in advance.

    Vassil



    #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 TestLimit : Strategy
    {
    #region Variables
    // Wizard generated variables
    private double distance = 2.0; // Default setting for Distance
    private double profit = 1.0; // Default setting for Profit
    private int timeBegin = 1000; // 10:00:00

    // User defined variables (add any user defined variables below)
    private double level1, level2, level3;

    #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()
    {
    CalculateOnBarClose = true;
    BarsRequired = 2;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    ExitOnClose = true;
    ExitOnCloseSeconds = 120;
    TraceOrders = true;
    ClearOutputWindow(); // just for easier debugging
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (ToDay(Time[0]) != ToDay(Time[1]))
    {
    level1 = level2 = level3 = 0;
    }

    if (Math.Floor(ToTime(Time[0]) / 100.0) == timeBegin)
    {
    level1 = Close[0] - 1 * distance;
    level2 = Close[0] - 2 * distance;
    level3 = Close[0] - 3 * distance;

    Print(Time[0] + " level1=" + level1 + " level2=" + level2 + " level3=" + level3);
    }

    if (level1 > 0 && level2 > 0 && level3 > 0)
    {
    EnterLongLimit(1, level1, "L1");
    EnterLongLimit(2, level2, "L2");
    EnterLongLimit(3, level3, "L3");

    ExitLongLimit(1, level1 + profit, "lx1", "L1");
    ExitLongLimit(2, level2 + profit, "lx2", "L2");
    ExitLongLimit(3, level3 + profit, "lx3", "L3");
    }
    }
    #region Properties
    [Description("")]
    [Category("Parameters")]
    public double Distance
    {
    get { return distance; }
    set { distance = value; }
    }
    [Description("")]
    [Category("Parameters")]
    public double Profit
    {
    get { return profit; }
    set { profit = value; }
    }
    [Description("")]
    [Category("Parameters")]
    public int TimeBegin
    {
    get { return timeBegin; }
    set { timeBegin = value; }
    }
    #endregion
    }
    }
    Attached Files

    #2
    vassil,

    You should not place your ExitLongLimit()s till after your entries actually fill.

    It may also be easier to just use SetProfitTarget() with CalculationMode.Price and you specifying the exact price you want for the profit target like you have already done with the ExitLongLimit()s.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      thank you for the prompt answer. I'll try that right now.
      Just I am a bit confused:
      Why can't I send the ExitLongLimit() orders together with the EnterLongLimit()'s?
      I could not find such constraint in the NT documentation (e.g. in
      http://www.ninjatrader-support.com/H...tml?Overview36 ).

      Thanks,

      Vassil

      Comment


        #4
        vassil,

        Technically you can, but there may be times when it won't be able to find the entry as the entry would not have been filled yet. With TraceOrders = true in Initialize() I suspect it to be full of messages in relation to that right now.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          yes, you are right - there are quite a few messages now.
          I am still not sure how this is the reason for the strategy not working correctly. But anyway, now I know that SetProfitTarget() is the better choise in this case.
          Thank you!

          Comment


            #6
            vassil,

            It may or may not be a factor, but with all the flooded messages it would be hard to debug and decipher the real reason. That is why you want to take it one step at a time.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you, Josh!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              639 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              572 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X