Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      Paul H.NinjaTrader Customer Service

      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.
          Paul H.NinjaTrader Customer Service

          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.
              Paul H.NinjaTrader Customer Service

              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.
                    Paul H.NinjaTrader Customer Service

                    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.
                        Paul H.NinjaTrader Customer Service

                        Comment


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

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by kulwinder73, Today, 10:31 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post kulwinder73  
                          Started by terofs, Yesterday, 04:18 PM
                          1 response
                          22 views
                          0 likes
                          Last Post terofs
                          by terofs
                           
                          Started by CommonWhale, Today, 09:55 AM
                          1 response
                          3 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by Gerik, Today, 09:40 AM
                          2 responses
                          7 views
                          0 likes
                          Last Post Gerik
                          by Gerik
                           
                          Started by RookieTrader, Today, 09:37 AM
                          3 responses
                          13 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X