No announcement yet.

Partner 728x90


limit order entries on a bar

  • Filter
  • Time
  • Show
Clear All
new posts

    limit order entries on a bar

    I wonder if this is possible?

    With my strategy if the price sits and just deviates on a per pip basis on a bar and that is the threshold of my order entry, every time the price moves an order is created.
    So before price moves one way or another multiple orders are created.

    Is there a way to limit orders on a bar to a maximum of say 2 ?
    using on bar close is not an option for me

    Appreciate any help
    Last edited by fredfred123; 09-28-2017, 03:01 PM.

    Hello fredfred123,

    You can limit the number of orders per bar or per day in the logic of your script.

    I would recommend you use integer as counter. On each order increment the counter. Require the counter be less than 2 to place a new order. Reset the counter to 0 on the first tick of a new bar.

    An example of limiting orders to one trade per day can be found on the forum post linked below.
    Chelsea B.NinjaTrader Customer Service


      Thank you for your reply

      would this set up the Integar ? I have called it Integar

      if all
      Do the following
      Integar = 1;
      I think to reset would be ( not sure where to put it? )

      If All
      Do This

      but would I make another set for it?

      Many thanks


        If I may clarify on my gaol

        I have a working strategy but have multiple trades opening in certain conditions. NT8

        I want to achieve the following

        Using the strategy builder the strategy will try to open up a trade when conditions are right

        When the logic of the strategy is right for a trade on a bar, a trade would be initialised.

        The problem arises when the bar that has just opened and is set to trade, but price fluctuates and the strategy will make multiple orders long and short as the price moves off the point that triggers the trade.

        My goal is only allow one trade when the bar opens when the strategy is ready to trade, I initially said two, but I think this complicates the issue. One will be fine

        The issue is focused on the one bar that has just triggered the trade. I have the calculation on each tick as On bar close will not work with this strategy.

        The focus is on that Bar that the strategy wants to place a trade on, and only allow the first trigger to trade.

        I see I could use an integer or bool to set a condition true or false, one or two for an integer, but not sure how I can make the script see the bar opening place the restriction for that bar of one trade only, and reset for the next bar ?

        Can this be done in the bounds of the Strategy Builder ? I don't want to unlock the code as this would stop me adding to it with the Strategy Builder.

        Not being a coder, and I could not find anything on the Ninja script videos with detail such as this, I am struggling and any help would be greatly appreciated.

        My previous post is my attempts to understand the workflow but is not working?

        The reference to a previous thread ( with thanks ) looks like a similar problem on a day basis and not on one bar, again I am not sure how I can relate it the Ninja script in the Strategy Builder. I tried to have a look at the download script for clues and it is an older version for NT8

        Many thanks
        Last edited by fredfred123; 09-29-2017, 04:49 AM.


          Hello fredfred123,

          I have created a quick demonstration video showing how you can use a doOnce bool to model the behavior you are looking for.


          Please let me know if this detail does not resolve your inquiry.
          JimNinjaTrader Customer Service


            Thank you Jim

            I have this so far?

            If the Entry condition sets (long or short)If all set1 has bool = true

            Do the following set bool = false

            now no more entries can be made until bool is set to true

            It is the reset when on a new bar starts that I can't work out. how is this reset to true on a new bar ?
            You mention on bar update, I am calculating on each tick so it would be the first tick of a new bar sets the bool back to True. What syntax would I use ?

            As your video shows I have another set, set2 has my entry condition then
            Do the following set bool =True

            but this part should only be set to true on a new bar?

            set 2 "if all' has the "entry condition"
            bit I can't grasp "only if a new bar"

            Do the following set bool to true

            Many thanks
            I have looked over old posts for this but I think some commands have changed in NT8?


              Hi Jim

              Did I miss this this as the set2 if All ?

              Default input(0)>=open(0)

              would that syntax be the new bar opening.

              then do the following reset bool to True

              If I have this right
              I have looked through the conditions and could you tell me where it is under ?

              I understand setting up the bool variable but am stuck setting the condition that reset the bool to true on a new bar.

              the aim is 1 bar = 1 trade only

              Many thanks
              Last edited by fredfred123; 09-29-2017, 12:16 PM.


                Hello fredfred123,

                There is a property called IsFirstTickOfBar that can tell you when a new bar is being built when Calculate is set to Calculate.OnEachTick. This property is not available in the Strategy Builder and will require manual programming.

                You may wish to write the strategy using the Strategy Builder, and then unlock the code to add a condition like below to reset the bool within OnBarUpdate().

                    doOnce = true;
                In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients. When unlocking the code, it is our expectation that you the developer can take the necessary steps to write the proper syntax and debug the code as needed throughout development. If you would like additional help in programming the code manually, I can have a member of our Business Development team provide some information on NinjaScript Consultants who would be happy to write the code for you.

                Here is a link on IsFirstTickOfBar for further reference:

                If there is anything else I can do to assist, please let me know.
                JimNinjaTrader Customer Service



                  I really do not want to unlock the code.

                  Is there another way round this with the strategy builder ?

                  such as "after the first trade don't make another till the next bar " ?

                  or after the first trade delay to next bar?

                  sorry this is the last piece in the jigsaw,

                  The Bool condition sets workflow to another Strategy Builder set just need to put something in there to stop any more trades till the next bar opens?



                    HI Jim

                    I have unlocked the code and have the following

                    Alert(@"TrendsMK3_2", Priority.Medium, @"Exit Long", @"", 600, Brushes.Transparent, Brushes.Green);
                    DoOnce = true;
                    I have the strategy as in the video.

                    The strategy is working ok, but is still making multiple trades in one bar ?
                    The code required the ";" after if(IsFirstTickOfBar)
                    Everything looks in the right place, is there anything else that should be in pace?
                    I am using playback for testing
                    May I send the script to see why this isn't working?

                    Many thanks
                    Last edited by fredfred123; 10-01-2017, 03:06 PM.


                      This code:
                      DoOnce = true;
                      will always execute the statement, "DoOnce = true;"

                      If the C# syntax checker required the ';' after if(IsFirstTickOfBar) then there is probably a syntax error somewhere else that you're not aware of. If you're willing to post more of your code surrounding this area, I might see the other syntax error.
                      Last edited by Conan108; 10-03-2017, 01:42 AM.


                        Many thanks for pointing that out, I will generate the code again from the Strategy Builder, and try a new script.

                        Thanks again for your offer to look at the code, Ill make sure I haven't any fat fingers when I try above and get back

                        Thanks again, appreciated.


                          HI Conan108

                          Many, Many thanks for that !

                          re-typed the code if(IsFirstTickOfBar)
                          DoOnce = true;

                          and didn't require the ";" and compiled fine. likely I disturbed something before.

                          script seems to working ok, giving it some testing!



                            I wish to extend my thanks to Ninjatrader_Jim (Great Video), ChelseB and Conar for the Patience and help you have given me as the solution to this problem has been resolved.

                            Great support thank you.


                            Latest Posts


                            Topics Statistics Last Post
                            Started by Aramunno, Today, 10:11 PM
                            0 responses
                            1 view
                            Last Post Aramunno  
                            Started by sdauteuil, Today, 09:38 PM
                            0 responses
                            Last Post sdauteuil  
                            Started by fscabrera03, Today, 09:23 PM
                            0 responses
                            Last Post fscabrera03  
                            Started by cormorea, Today, 09:08 PM
                            0 responses
                            Last Post cormorea  
                            Started by WeyldFalcon, Today, 07:03 PM
                            0 responses
                            Last Post WeyldFalcon