Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Orders placed over and over on the same bar

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

    Orders placed over and over on the same bar

    Once a condition is met the strategy puts in a order. Works great BUT...

    Say on a 5 min bar it goes pending/fills/reaches target in 2 minutes, the strategy immediately puts in another pending order as there is 3 minutes left until the current bar closes.

    How do you only have the strategy put in only 1 order per bar?

    Thanks in advance.

    #2
    Hello,

    This is happening because you do not have a condition to stop the next order from being placed. An new tick is coming in and the conditions still qualify for another trade. I recommend building a bool flag that get turned on and off each time a trade is placed and exited and inlucde that in your conditions to trade.
    DenNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ben View Post
      Hello,

      This is happening because you do not have a condition to stop the next order from being placed. An new tick is coming in and the conditions still qualify for another trade. I recommend building a bool flag that get turned on and off each time a trade is placed and exited and inlucde that in your conditions to trade.
      Do you have an example as I don't know how to code...

      Comment


        #4
        For example (untested code)

        Code:
        // In Variables region of code
        private bool boolFlag = true;
        
        // In OnBarUpdate()
        if (some condition && boolFlag == true)
        {
             EnterLong();
             boolFlag = false;
             entryBarNumber = CurrentBar;
        }
        
        if (boolFlag == false && CurrentBar != entryBarNumber)
        {
             boolFlag = true;
        }
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Excellent let me try it out.

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            For example (untested code)

            Code:
            // In Variables region of code
            private bool boolFlag = true;
            
            // In OnBarUpdate()
            if (some condition && boolFlag == true)
            {
                 EnterLong();
                 boolFlag = false;
                 entryBarNumber = CurrentBar;
            }
            
            if (boolFlag == false && CurrentBar != entryBarNumber)
            {
                 boolFlag = true;
            }

            Josh,

            I've plugged in the code and compiled to get this Error:

            "The name 'entryBarNumber' does not exist in the current context" Code CS0103.

            So clicked on the link for Code CS0103 so I tried adding:

            #region Variables
            int entryBarNumber = 0;

            Still doesn't work but no compile error...

            Comment


              #7
              private int entryBarNumber = 0;

              You can add Print() inside the if-statements to see where it is each step of the way. You will want to see what the boolFlag is set to. As long as it is false, you will not be able to place in additional trades. If you feel you are getting entry orders, then the boolFlag would be true and you will need to isolate out where it is getting set to true at.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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