Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entries Count per minute

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

    Entries Count per minute

    If I am backtesting an entire index of stocks say the nadaq, how would I go about limiting each individual instrument to 1 trade per minute. I assume I would use a bool statement somehow?

    #2
    Hello zachj,

    Thank you for your post.

    Is the strategy ran on 1 minute bars? If so, you can use BarsSinceEntry() to ensure one bar has passed before submitting a new order. BarsSinceEntry(): http://www.ninjatrader.com/support/h...sinceentry.htm

    There are other methods to do this if not using 1 minute bars; such as a ToTime() check: http://www.ninjatrader.com/support/h...nt7/totime.htm

    Please let me know if you have any questions.

    Comment


      #3
      I actually would like to do only one entry per 10min per instrument. 5min is primary series so I would just do?..

      if (BarsSinceEntry() > 2)

      I'm running a backtest on the whole Nasdaq 100, will this stop it from entering any new positions within 10min for all instruments or will this be only one entry per 10min per instrument? I was looking for just per instrument.

      Comment


        #4
        Hello zachj,

        Thank you for your response.

        If you are using a larger time frame than one minute you can use CalculateOnBarClose = false for real-time data and add a ToTime() check to check if one minute had passed. For backtesting you would have to add in an additional data series (1 minute) as backtesting is always done on historical data so CalculateOnBarClose is always true.

        For a reference sample on adding an a smaller timeframe for backtesting please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=6652

        Comment


          #5
          Yes I'm just doing backtesting. Would like only one entry per 10minutes per instrument. 5min is primary series so as mentioned I would just have?..
          if (BarsSinceEntry() > 2)

          Is this correct?

          Comment


            #6
            Hello zachj,

            That would be correct to ensure two bars have closed since your entry.

            Comment


              #7
              I am using... if (BarsSinceEntry() > 5). Just using a 10min time frame, not looking at any other time frame. So basically I want to stop it from triggering a trade if it's already traded in the last 50-60min. When I add this to the script though it doesn't pick up any trades now. I put this in the OnBarUpdate() section. Any idea what could be happening? Code below

              update: I found this from another post.. "You cannot use that condition like that because for the very first trade there was no BarsSinceEntry() > 5. You will need to code a set for the first trade and a separate set for subsequent trades you wish to use the BarsSinceEntry logic with. "

              So how would I accomplish what is being suggested?

              Code:
               if (BarsSinceEntry() > 5)
              {
               
                 if (Close[0] > (Open[0]*percmove)) 
                    { 
                      EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                    }
               
                else if (Close[0] > (Open[1]*percmove)) 
                    { 
                      EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                    }
              }
              Last edited by zachj; 08-08-2013, 12:15 PM.

              Comment


                #8
                Hello zachj,

                Thank you for your post.

                The thread you quoted is absolutely correct, you will need to enter that first trade without that condition check. So you could create a bool that is true when the strategy starts, the first trade checks for the bool to be true and enters the first trade as well as sets the bool to false.

                Please let me know if you have any questions.

                Comment


                  #9
                  I tried this below but still is not entering any trades, is anything off?

                  Code:
                   
                  bool entertradecondition = false;
                   
                  Trade firstTrade = Performance.AllTrades[0]; 
                   
                       if (firstTrade == null)[INDENT]
                  [LEFT]{
                  
                  entertradecondition = true;
                  }[/LEFT]
                  [/INDENT]else[INDENT]{
                  entertradecondition = BarsSinceEntry()>5; 
                  } 
                  [/INDENT]if (entertradecondition)
                   
                  {[INDENT]if (Close[0] > (Open[0]*percmove)) 
                   { 
                     EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                   } 
                   
                  else if (Close[0] > (Open[1]*percmove)) 
                   { 
                    EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                   }
                  [/INDENT]}

                  Comment


                    #10
                    Hello,

                    Thank you for your response.

                    I would have done something more similar to the following:
                    Code:
                    bool entertradecondition = true;
                     
                    if(entertradecondition)
                    {
                    if(YourFirstEntryCondition)
                    {
                    //Your Entry
                    entertradecondition = false;
                    }
                    }
                     
                    if(!entertradecondition)
                    {
                    if (Close[0] > (Open[0]*percmove)) 
                     { 
                       EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                     } 
                     
                    else if (Close[0] > (Open[1]*percmove)) 
                     { 
                      EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                     }
                    }

                    Comment


                      #11
                      Hello zachj,

                      You may be getting an OnBarUpdate error in your log tab about accessing an index with a value that is invalid.

                      This would be due to the Performance.AllTrades[0] call.

                      Instead use if (Performance.AllTrades.Count < 1).

                      Attached is a sample strategy I have made to demonstrate this.

                      Be sure to open your Output window so that you can see the prints I added.
                      Attached Files
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I tried incorporating your example into my script below but still not getting a trade. See anything obvious I may be missing?....

                        Code:
                            protected override void OnBarUpdate()
                           {
                             if (Historical)
                        	 return;
                        
                             bool enterTrade = false;
                        
                            if (Performance.AllTrades.Count <1) 
                        
                             {
                               enterTrade = true;
                             }
                            else
                             {
                               enterTrade = BarsSinceEntry() > 5; 
                             } 
                        
                                  if (enterTrade)
                        			{
                        				if (Position.MarketPosition == MarketPosition.Flat)
                        			
                        			  {		
                        				   if (Close[0] > (Open[0]*percmove)) 
                        				{	
                        				    EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                        				}
                        				
                        				   else if (Close[0] > (Open[1]*percmove)) 
                        				{	
                        				    EnterLong(Convert.ToInt32(Math.Round(1000/Close[0])));
                        				}
                        				
                        			  }
                        			}	
                        			
                                                //If profit is >=1 set trail at 100 ticks
                        			if (Position.MarketPosition == MarketPosition.Long && Close[0] > Position.AvgPrice + 1)
                        				
                        			{
                        				SetTrailStop(CalculationMode.Ticks, 100);
                        			}
                        			
                        			if (Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) >= 155000)
                        			  {
                                                       ExitLong();
                        	                  }
                        			
                           }

                        Comment


                          #13
                          Hi Zachj,

                          I am testing out the code on my end.

                          What value do you assign to percmove.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Well I was using an extreme amount but I would just go with 5% to be able to get some trades to trigger especially seeing it's only looking back 1 bar. I left the additional else if's out that looked back as far as 6 bars in relation to the current bar Close just to simplify the code.

                            Comment


                              #15
                              Zachj,

                              Thank you for the reply.

                              I am able to get trades coming through on my end with the percmove set to 5%.

                              Can you confirm that if you use the 5% and simplified your strategy can you get trades to take place?
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              577 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 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
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X