Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

One Order Per Bar

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

    One Order Per Bar

    Is there code that I can put in my strategy that makes it only enter a new order on a bar that hasn't just closed on a trade without it being set on calculate on bar close? I want the setting of calculate on bar close = false because I get better entries but I don't want it to put in a new order right after it closes a trade on the same bar because that can really screw things up sometimes. I want it to wait until the next bar to enter the new order after the close of the previous order.

    I hope that makes sense. Thanks for any help.

    #2
    cre8it8, you can work with BarsSinceExit() in your entry conditions to avoid reentering on the same bar then - http://www.ninjatrader-support.com/H...SinceExit.html

    Comment


      #3
      That looks great. Thanks for the fast reply and help Bertrand.

      Comment


        #4
        Is there a reason this is not running correctly? Is there something I need to add in order to use BarsSinceExit? This ran fine before I added it. Thanks.

        if (SMA(9)[0] -0 * TickSize > SMA(20)[0])
        {
        if (Position.MarketPosition == MarketPosition.Flat
        && BarsSinceExit() >0 )
        {
        EnterLong(1, "Long 1a");

        }

        Comment


          #5
          This will not be picked up, as your signal names do not match unfortunately.

          Comment


            #6
            I tried changing BarsSinceExit() >0 to BarsSinceExit("Long 1a") >0 and it didn't seem to work. Something I am missing?

            Comment


              #7
              cre8it8, please try just with emtpy "" signal names for a test.

              You can also work with a bool flag here and reset it for example then on FirstTickOfBar so you can take trades again.

              Comment


                #8
                Odd, I created a strategy with the example from the link you gave me and it didn't work when I ran it. Is there something that needs to be put into the variables section or somewhere to make the below work.



                protected override void OnBarUpdate()
                {
                if (CurrentBar < 20)
                return;

                // Only enter if at least 10 bars has passed since our last exit
                if (BarsSinceExit() > 10 && CrossAbove(SMA(10), SMA(20), 1))
                EnterLong();
                }

                Comment


                  #9
                  cre8it8,

                  If your strategy has never traded yet, BarsSinceExit() would never be greater than 10. This would mean you would also never trade so you have a catch-22 situation there. You will need to allow for the first trade before using that type of condition.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I see. I think I can work with that info. I will give a few things a try and see what happens. Thanks Josh.

                    Comment


                      #11
                      So I tried a couple of things like have the code without the BarsSinceExit and then have the code below that with it but to no result. Can you give me an example of how you would get it to allow the first trade and then after that trade go to the code with the BarsSinceExit. Thanks Josh

                      Comment


                        #12
                        Not that you asked me... But, here is what I've done.

                        In variables...
                        private bool OneBarSinceExit = true;



                        Then inside the OnBarUpdate:
                        if (BarsSinceExit() > 1)
                        OneBarSinceExit = true;


                        Prior to initiating a trade and along with your other checks, make sure OneBarSinceExit is true.


                        After a trade is sent, reset OneBarSinceExit back to false. It is important that OneBarSinceExit is set to true in the variables. Or else it never makes that first trade.

                        Comment


                          #13
                          Thanks for jumping in "look out below" your opinion is valued. I tried to do what you suggested on some easy code but I couldn't get it to work. I am fairly amateur at programming and most of what I am able to do is from looking at others sample codes and figuring out how to create what I need. Here is what I tried to do with what you told me below. Am I even close? Thanks for your help.

                          #region Variables
                          private bool OneBarSinceExit = true;
                          #endregion

                          protected override void Initialize()
                          {
                          EntriesPerDirection = 1;
                          CalculateOnBarClose = false;
                          SetProfitTarget("Long 1a", CalculationMode.Ticks, 5);
                          ExitOnClose = false;
                          }

                          protected override void OnBarUpdate()
                          {
                          if (BarsSinceExit() > 1)
                          OneBarSinceExit = true;

                          if (SMA(9)[0] > SMA(20)[0]&& OneBarSinceExit == true)
                          {
                          EnterLong(1, "Long 1a");
                          OneBarSinceExit == false;
                          }
                          }
                          }

                          #region Properties
                          #endregion
                          }
                          }

                          Comment


                            #14
                            I think if you left everything you did the same, but change:

                            EnterLong(1, "Long 1a");
                            OneBarSinceExit == false;

                            to

                            EnterLong(1, "Long 1a");
                            OneBarSinceExit = false;


                            You have an extra "=" in there. I haven't had much sleep lately, so I may be overlooking something. But, that should work.

                            Comment


                              #15
                              cre8it8, please try what lookOutBelow has suggested and if it doesn't work, let us know.
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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