Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A single order

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

    A single order

    Good Morning,

    I'm setting a strategy and I would like to know what function should I use to only perform a single operation. That is, once you complete an operation will not send more orders.

    Thank you very much.

    #2
    Make sure/set EntriesPerDirection to 1.

    Comment


      #3
      Hello condealvaro6,

      Thanks for your post.

      You can use a bool (true/false) to control. Example:

      Code:
      if (your conditions for entry && doitOnce)
      {
      // order entry logic here
      doitOnce = false;  // set to false so will only execute once
      }
      Note: the bool doitOnce is declared as true in the variables section.

      Comment


        #4
        good afternoon,

        I followed your instructions and I can think of something very rare. In entries in long works perfectly. However, in the short entries automatically it changes the bool variable value from true to false.

        I appreciate your help.

        Comment


          #5
          Hello condealvaro6,

          Thanks for your reply.

          The only place that the bool doitOnce is set true is in the variables section so that when the strategy starts the condition is true. When the strategy executes and your entry condition is met and the order is placed, the bool is then set to false and that would prevent any other entry orders from occurring. If you used the same bool in both a long entry and a short entry then that would meet your original requirement of 1 entry.

          If you are wanting to have one long and one short then you would need to add another bool specifically then for the other case.

          Please let me know if I am not understanding your goals correctly.

          Comment


            #6
            Thanks for your answer.

            You have understood perfectly what I do. The problem is that we declare two variables as you say, the first for long entries (doitOnceUp), and the second for short entries (doitOnceDown). Still, when I launch the strategy doitOnceUp value variable is true but doitOnceDown automatically switches to false.

            It's very strange because the two variables are declared in the variables section to true.

            Comment


              #7
              Hello condealvaro6,

              Thanks for your reply.

              Without seeing the code I suspect that the wrong bool is used in one entry or the other or the wrong bool is set false in the wrong place.

              If you like you can post your code here or you can send it in to Platformsupport[at]Ninjatrader[dot]com with atten Paul and a link to this thread.

              Comment


                #8
                Thank you.

                Basically the code is as follows:

                #region Variables
                private bool doitOnceUp = true;
                private bool doitOnceDown = true;
                #endregion

                protected override void OnBarUpdate()
                {
                if (Condition1 && doitOnceUp)
                {
                EnterLong(DefaultQuantity, "");
                doitOnceUp = false;
                }

                if (Condition2 && doitOnceDown)
                {
                EnterLong(DefaultQuantity, "");
                doitOnceDown = false;
                }
                }


                I do not understand where this failure.

                Comment


                  #9
                  What about historical processing?

                  Do you have something like this inside OnBarUpdate?

                  if (historical) return;

                  Comment


                    #10
                    Hello condealvaro6,

                    The only item out of place is that you are using EnterLong with condition 2.

                    Comment


                      #11
                      Thank you very much to you both for your response.

                      First on the condition2 I have EnterShort, has been a fault of mine, I'm sorry.

                      On the other hand the historical processing is not that is not where to look.

                      Comment


                        #12
                        Hello condealvaro6,

                        Thanks for your post.

                        It is not clear if the issue has been resolved. Assuming it has not what I recommend is that you add print statements throughout your code so that you can understand the various conditions as they occur. For example:

                        Print ("Time: "+Time[0]+ "doitOnceUp: "+doitOnceUp+" doitOnceDown: "+doitOnceDown);

                        This will output the date and time and the true or false condition of each of the two bools. You could use the print statement in a few places (maybe add a label prior to "Time like "1-Time:..." or "2-Time:..." so you know which print line executes). This is how you begin the debugging process by exploring the conditions that exist and when they exist and then digging deeper until you find the root cause.
                        Last edited by NinjaTrader_PaulH; 07-22-2015, 02:01 PM.

                        Comment


                          #13
                          Thank you very much for the help, is solved.

                          Comment

                          Latest Posts

                          Collapse

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