Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Filter

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

    Time Filter

    Why is this time filter allowing some trades to happen outside the time range.
    Code:
    && ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000)
     || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
    Thanks in advance.

    #2
    Hammerhorn, you mean you see fresh entry signals happen (those that would be presumably filtered by your condition snippet posted) during a time which you would not expect?

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hammerhorn, you mean you see fresh entry signals happen (those that would be presumably filtered by your condition snippet posted) during a time which you would not expect?
      Correct, trades are happening outside of the time range.

      Comment


        #4
        Would suggest you then visually idenfiy the areas where it would evaluate to true so you can debug the condition for your setup - is this being worked from a tick or time based chart?

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Would suggest you then visually idenfiy the areas where it would evaluate to true so you can debug the condition for your setup - is this being worked from a tick or time based chart?
          There is not one specific time, according to the distribution chart (entry), it happens at all times. Tick chart, volume in particular.

          Comment


            #6
            The time filter you posted itself look accurate to me, would suggest simplifying your script and debugging where the additional entries are coming from - there's no ambiguity here - the code will evaluate when the conditions dictate it to.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              The time filter you posted itself look accurate to me, would suggest simplifying your script and debugging where the additional entries are coming from - there's no ambiguity here - the code will evaluate when the conditions dictate it to.
              See images, which are just back tests of the codes below with the exact same parameters. Notice the slight differences in and out of the intended time filter. I am stumped on a solution.

              Image, "SimplewithTimeFilter," is of this very simple code with a time filter.

              Code:
              // Condition set 1
                          if (Close[1] > Close[2]
                              && Close[2] > Close[3]
                              && Close[3] >= Close[4]
                              && BarsSinceExit() > 2 || BarsSinceExit() == -1
                              && ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000)
                              || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
                          {
                              EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, "");
                          }
                          
                           // Condition set 1
                              if (Close[1] < Close[2]
                              && Close[2] < Close[3]
                              && Close[3] <= Close[4]
                              && BarsSinceExit() > 2 || BarsSinceExit() == -1
                              && ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000)
                              || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
                          {
                              EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, "");
                          }
              Image, "SimplewithoutTimeFilter," is of this very simple code without a time filter.

              Code:
               // Condition set 1
                          if (Close[1] > Close[2]
                              && Close[2] > Close[3]
                              && Close[3] >= Close[4]
                              && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                          {
                              EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, "");
                          }
                          
                           // Condition set 1
                              if (Close[1] < Close[2]
                              && Close[2] < Close[3]
                              && Close[3] <= Close[4]
                              && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                          {
                              EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, "");
                          }
              Attached Files

              Comment


                #8
                Thanks, I see - I would suggest restructuring the code to this version -

                Code:
                if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
                	{	
                					// Condition set 1
                					if (Close[1] > Close[2]
                						&& Close[2] > Close[3]
                						&& Close[3] >= Close[4]
                						&& BarsSinceExit() > 2 || BarsSinceExit() == -1)
                				{
                					EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, "");
                				}
                				
                					// Condition set 1
                					if (Close[1] < Close[2]
                						&& Close[2] < Close[3]
                						&& Close[3] <= Close[4]
                						&& BarsSinceExit() > 2 || BarsSinceExit() == -1)
                				{
                					EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, "");
                				}
                        	}

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  Thanks, I see - I would suggest restructuring the code to this version -

                  Code:
                  if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
                      {    
                                      // Condition set 1
                                      if (Close[1] > Close[2]
                                          && Close[2] > Close[3]
                                          && Close[3] >= Close[4]
                                          && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                                  {
                                      EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, "");
                                  }
                                  
                                      // Condition set 1
                                      if (Close[1] < Close[2]
                                          && Close[2] < Close[3]
                                          && Close[3] <= Close[4]
                                          && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                                  {
                                      EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, "");
                                  }
                              }
                  Thank you, but why? What if I wanted different times for long and short?

                  Comment


                    #10
                    The reason is because of the short circuit evaluation of your boolean && + || statements here having nested the time filter into the main condition. If you would like different times for longs / shorts you can move it of course directly before the if part submitting the final order as well to make more flexible -


                    Code:
                    	  if (Close[1] > Close[2]
                                    && Close[2] > Close[3]
                                    && Close[3] >= Close[4]
                                    && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                                    //&& ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
                                {
                    	if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
                                    	EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, "");
                                }
                                
                               
                                    if (Close[1] < Close[2]
                                    && Close[2] < Close[3]
                                    && Close[3] <= Close[4]
                                    && BarsSinceExit() > 2 || BarsSinceExit() == -1)
                                    //&& ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
                                {
                    	if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
                                    	EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, "");
                                }

                    Comment

                    Latest Posts

                    Collapse

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