Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to limit entries to one

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

    how to limit entries to one

    A strategy that I am testing will enter 2 positions long or short many times.
    How can I limit the positions to only one at a time ?

    thanks
    shane

    #2
    shane,

    You can use entries per direction here :

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      hi
      yes, it is set to one entry per direction and all entries.
      thats why I am confused

      thanks
      shane

      Comment


        #4
        Shane,

        I may need to see a code sample of your order entry and maybe even initialize method. You could always obfuscate the entrance conditions, etc. if you don't want to share everything.

        for example :

        if ( CrossAbove(SMA(10),SMA(25),1) )
        {

        EnterLong();

        }

        All I need is :

        if ( my_conditions_are_here )
        {

        EnterLong();

        }
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          /// <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(RSI(Period, Smooth));
          Add(RSI(Period, Smooth));
          Add(RSI(Period, Smooth));
          Add(RSI(Period, Smooth));
          SetStopLoss("", CalculationMode.Percent, 1, false);

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Rising(RSI(Period, Smooth).Avg) == true
          && RSI(Period, Smooth).Avg[0] > 60)
          {
          EnterLong(DefaultQuantity, "");
          }

          // Condition set 2
          if (Falling(RSI(Period, Smooth).Avg) == true)
          {
          ExitLong("", "");
          }

          // Condition set 3
          if (Falling(RSI(Period, Smooth).Avg) == true
          && RSI(Period, Smooth).Avg[0] < 40)
          {
          EnterShort(DefaultQuantity, "");
          }

          // Condition set 4
          if (Rising(RSI(Period, Smooth).Avg) == true)
          {
          ExitShort("", "");
          }
          }

          #region Properties
          [Description("")]
          [GridCategory("Parameters")]
          public int Period
          {
          get { return period; }
          set { period = Math.Max(1, value); }
          }

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

          Comment


            #6
            Shane,

            I think the issue is here :

            Code:
            // Condition set 2
            if (Falling(RSI(Period, Smooth).Avg) == true)
            {
            ExitLong("", "");
            }
            
            // Condition set 3
            if (Falling(RSI(Period, Smooth).Avg) == true
            && RSI(Period, Smooth).Avg[0] < 40)
            {
            EnterShort(DefaultQuantity, "");
            }

            These can occur at the same time. I would suggest trying the following :

            Code:
            // Condition set 1
            if (Rising(RSI(Period, Smooth).Avg) == true
            && RSI(Period, Smooth).Avg[0] > 60)
            {
            EnterLong(DefaultQuantity, "");
            }
            // Condition set 4
            else if (Rising(RSI(Period, Smooth).Avg) == true)
            {
            ExitShort("", "");
            }
            
            
            // Condition set 3
            if (Falling(RSI(Period, Smooth).Avg) == true
            && RSI(Period, Smooth).Avg[0] < 40)
            {
            EnterShort(DefaultQuantity, "");
            }
            // Condition set 2
            else if (Falling(RSI(Period, Smooth).Avg) == true)
            {
            ExitLong("", "");
            }
            You may also want to check that your "Default Quantity" is set to 1 in your strategy properties when you run a backtest or attach to a chart.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              thanks

              default is set to 1

              thanks for your help

              shane

              Comment


                #8
                i dont understand how your code is doing something different, can you explain ?

                thanks

                shane

                Comment


                  #9
                  Originally posted by shanemcdonald View Post
                  i dont understand how your code is doing something different, can you explain ?

                  thanks

                  shane
                  The answer to your question, and pretty much the question itself, is the same as the answer that I gave in this thread.

                  ref: http://www.ninjatrader.com/support/f...ing#post264727

                  Comment


                    #10
                    koganam

                    thanks that is a good thread.
                    Thanks for the info

                    shane

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Started by yertle, Today, 08:38 AM
                    5 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by adeelshahzad, Today, 03:54 AM
                    3 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by bill2023, Yesterday, 08:51 AM
                    6 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Working...
                    X