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

Limiting Trades per bar

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

    Limiting Trades per bar

    Hello guys,
    is there a way of limiting the number of trades executed per bar? Im using an intrabar strategy and I want to only execute a maximum of two trades per bar. Thanks for your help in advance

    #2
    Hi there, in order to limit the number of trades per bar, I would recommend monitoring the number of trades placed while inside the secondary (more fine) instrument's BarsInProgress index and resetting the value for every main bar update. Then you can tell the strategy to not place any more trades if it has already placed two.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks Austin,I will let you know if I have any more questions.
      thanks

      Comment


        #4
        Same Problem

        I would also like to just make 2 trades per bar in a strategy that is set to On Bar Update False. I tried the Performance.AllTrades.TradesPerformance.MaxConsecW inner < 2 but I had to manually turn it off and on to reset for the next bar. Could I possibly get a piece of sample code for the problem solve suggested here. I looked at the Sample Data Series code but I didn't see how one would reset after the main bar update also how you would keep track of the number of trades executed in the lower time frame.

        Thanks for any help.

        Comment


          #5
          cre8it8, you will need some sort of counter to keep track of how many orders have been placed per bar, and then reset at the first tick of every new bar with FirstTickOfBar.

          The could would probably look something like this:
          Code:
          OnBarUpdate()
          {
             if (FirstTickOfBar)
                 thisBarTrades = 0;
          
             if (long entry conditions are true)
             {
                EnterLong();
                thisBarTrades = thisBarTrades + 1;
              }
              if (short entry conditions are true)
              {
                 EnterShort();
                 thisBarTrades = thisBarTrades + 1;
               }
          }
          You would need to monitor all of this in the small timeframe's BarsInProgress context:
          Code:
          OnBarUpdate()
          {
            if(BarsInProgress == 1) // assuming the secondary series (1) is the smaller timeframe
            {
                // all of the code I posted above + your code
             }
          }
          Please let me know if you have any other questions.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Thanks Austin for trying to help but it appears to be out of my league so I am going to use the strat I have now and if I like how things are going manually I will pay one of the pros to program it the better way for me.
            Thanks again for getting back to me.

            Comment


              #7
              cre8it8, if you are looking for a list of "pros", you can find our 3rd party NinjaScript consultant list here.
              AustinNinjaTrader Customer Service

              Comment


                #8
                Limiting Trades per Bar

                It took me a day to figure this out even after reading this thread. An alternative approach without using multi-series time frames (due to the use of countif() in your strategy or for any other reason) is to increment your counter within OnExecution(). Use FirstTickofBar to reset your counter within the same time frame. Within OnExecution() each order fill (buy & sell) is regarded as one count event apiece. Thus, if you want to have 2 trades per bar, the count condition would be

                if(tradeCounter < 4)
                { Keep trading....}

                Hope this helps...

                Comment


                  #9
                  Hello,
                  You can use the Performace class to know who many trades has been taken.
                  Code:
                  this.Performance.RealtimeTrades.Count
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Limit Trades per Bar

                    Using

                    this.Performance.RealtimeTrades.Count

                    how do you reset the counter from FirstTickofBar?

                    Comment


                      #11
                      Hello geekodude,
                      Realtime trades will return any trades which was taken live and not on historical data.

                      No, the count is not re-set'ed on FirstTickOfBar.
                      JoydeepNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by sdauteuil, 09-23-2021, 10:16 AM
                      7 responses
                      1,247 views
                      0 likes
                      Last Post marcus2300  
                      Started by sofortune, 05-18-2024, 11:48 AM
                      2 responses
                      32 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by Zach55, 02-19-2024, 07:22 PM
                      2 responses
                      65 views
                      0 likes
                      Last Post lbadisa1  
                      Started by JGriff5646, Yesterday, 05:47 PM
                      1 response
                      14 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by AlphaOptions, 06-18-2013, 08:24 AM
                      9 responses
                      2,203 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X