Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Filter Not Working

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

    Time Filter Not Working

    I am using the following code to limit my trades to certain time periods of the day. I have used this code in dozens of strategies and it has always worked. Today, for some reason, in this strategy it does not work. In theory I should only be seeing trades initiated between the hours of 06:00 and 09:00 but when I test it, or run it in real time I get trades outside this period. Is there something wrong with my code? Here it is:

    Code:
            
    #region Variables
    		private int tt1_Start = 60000 ; // Start Time for first trading period
    		private int tt1_End = 90000 ; // End Time for first trading period
    		private int tt2_Start = 83000 ; // Start Time for second trading period
    		private int tt2_End = 83000 ; // end Time for second trading period
    #endregion
    
    && ((ToTime(Time[0]) > TT1_Start && ToTime(Time[0]) < TT1_End ) || (ToTime(Time[0]) > TT2_Start && ToTime(Time[0]) < TT2_End )))
    
            #region Properties
            [Description("")]
            [Category("Parameters")]
            public int TT1_Start
            {
                get { return tt1_Start; }
                set { tt1_Start = Math.Max(000001, value); }
            }
    		
            [Description("")]
            [Category("Parameters")]
            public int TT1_End
            {
                get { return tt1_End; }
                set { tt1_End = Math.Max(000001, value); }
            }
    		
            [Description("")]
            [Category("Parameters")]
            public int TT2_Start
            {
                get { return tt2_Start; }
                set { tt2_Start = Math.Max(000001, value); }
            }
    		
            [Description("")]
            [Category("Parameters")]
            public int TT2_End
            {
                get { return tt2_End; }
                set { tt2_End = Math.Max(000001, value); }
            }		
            #endregion

    #2
    Hello,

    Your code looks fine - I ran a sample with this code and I only see trades executed within these parameters when backtesting.

    Is there anything outside of this block that would be placing orders?

    If you use this code in another script, does it work - is it just this particular script that does not function as intended?

    You will need to simplify the rest of the strategy to determine why this filter is not being considered.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Time Filtered Trading

      Matthew,
      I use this code block all the time in all kinds of strategies and it has worked every time. I only time the trade entries. It is possible for a conditioned exit (if marketposition -- long, or short) to exit a trade at any time, but new positions can only be initiated within the timed window. when I backtest this strategy using strategy analyzer I get trades at all hours. When I put it on a chart and look at performance I get trades at all hours. It is the weirdest thing. Is it possible that my instance of NT is somehow corrupted and that is why the time filter isn't working now?

      Comment


        #4
        I just ran another strategy that I have used before and has the same code block in it and it is only executing during the defined trade windows. For some reason it is just this strategy that is misbehaving.
        DaveN

        Comment


          #5
          Hello,

          Do you have any templates for this strategy saved under (My) Documents\NinjaTrader 7\templates\Strategy? If so, can you delete this .xml file and test again?

          You might want to try creating a new instance of this strategy by right clicking in the code windows--> select "Save As" and give it a new name. Then run a back test on the newly named strategy and see if you get the same results.
          MatthewNinjaTrader Product Management

          Comment


            #6
            I'm not sure how to save a strategy template or what it even is. I'm only familiar with chart templates and ATM Templates. I did save the strategy under a new name and compiled and put it on an existing chart and looked at the history and I still got trades outside of the trade window filter. Can you direct me to any information about NinjaScript Strategy Templates?
            Thanks
            DaveN

            Comment


              #7
              Strategy templates are saved when you right click on the strategy parameters and select "Set Default for <strategy>
              MatthewNinjaTrader Product Management

              Comment


                #8
                Just an update Matthew. I copied an old strategy that had the time filter working, added my new trade entry criteria from the strategy that it wasn't working in, and everything worked find. I have no idea why, in this one particular strategy the time filter didn't work, but I was able to work around it. Thanks for your help.
                DaveN

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                4 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                41 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                20 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Working...
                X