Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Filter Problems

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

    Time Filter Problems

    There seems to be something wrong with my time filter. (See sample code below).
    If enable my strategies on Sunday the try to open a position immediately. But they should wait until Monday 6 am. (Im am trading Forex).
    In the options strategies tab I have enabled "Immediatly submit live working orders". "Sync account position" is set to "true".
    What would be the best way to quickly open a position on Monday morning?
    And could you please clarify to which time zone the time codes are referring. The computer clock or UTC?
    Thanks
    Soren

    Code:
    /// </summary>
            protected override void OnBarUpdate()
            {
                // Start: Time Filter
    			
    			if (Time[0].DayOfWeek != DayOfWeek.Saturday && Time[0].DayOfWeek != DayOfWeek.Sunday)
    			{
    			
    				if (Time[0].DayOfWeek == DayOfWeek.Monday && ToTime(Time[0]) >= 060000
    				|| Time[0].DayOfWeek == DayOfWeek.Tuesday && ToTime(Time[0]) >= 000000
    				|| Time[0].DayOfWeek == DayOfWeek.Wednesday && ToTime(Time[0]) >= 000000
    				|| Time[0].DayOfWeek == DayOfWeek.Thursday && ToTime(Time[0]) >= 000000
    				|| Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 180000)
    			// End: Time Filter			 
    				{
    			// Start: Strategy logic 	 
    				
    					// Condition set 1
    					if (SMA (S) [0] > SMA (S)[1])
    					{
    						EnterLong(DefaultQuantity, "");
    					}
    
    					// Condition set 2
    					if (SMA (S) [0] < SMA (S)[1])
    					{
    						EnterShort(DefaultQuantity, "");
    			
    					}
    			// End: Strategy logic 
    				}
    			}
    			// Start: Time Filter Exit on Friday		
    			
    			if (Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 180000)
    			{
    				ExitLong();
    				ExitShort();
    			}
    			// End: Time Filter Exit on Friday
    			
    			
            }

    #2
    Hi Moon_121,

    Thank you for your post.

    What kind of chart interval are you running this on?

    Your code looks fine and should not be submitting orders on the Sunday time frame.
    Although another way to write this would be to not use the != check that you have and check if it is Sunday or Saturday and return it so that the strategy doesn't process anything.
    Code:
    if(Time[0].DayOfWeek == DayOfWeek.Saturday || Time[0].DayOfWeek == DayOfWeek.Sunday)
         return;
    Yes, the setup you have will immediately start trades with no regard to the Account Position prior to starting.

    The code will utilize the time based on the chart display, If you enable the data box, and hover over a bar, that time is the time that the code will grab.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the clarification. I am using a Renko based custom chart type. I know the can be a bit tricky.
      But still: If the strategy forbids to trade on Sundays, it should not try to open a position - even on a Renko chart (at least not , if there was a clear exit on Friday with more bars on the chart after the exit.)
      To avoid errors, could you please show me how you would integrate the time filter for Monday (execute after 6 am) and the code in your example? I am not sure, whether to start with a new "If" after the "return" command.

      Comment


        #4
        Moon_121,

        The account sync set to true does not care about the conditions. It will submits orders to the account so that the account position will match the historical strategy position.

        I'm attaching a link on Syncing account positions -
        http://www.ninjatrader.com/support/h..._positions.htm
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          To avoid errors, could you please show me how you would integrate the time filter for Monday (execute after 6 am) and the code in your example? I am not sure, whether to start with a new "If" after the "return" command.

          Comment


            #6
            Moon_121,

            Yes, you would need to the use the same IF statement for the Monday thru Friday time filter.

            Code:
            if(Time[0].DayOfWeek == DayOfWeek.Saturday || Time[0].DayOfWeek == DayOfWeek.Sunday)
                 return;
            
            if (Time[0].DayOfWeek == DayOfWeek.Monday && ToTime(Time[0]) >= 060000
            				|| Time[0].DayOfWeek == DayOfWeek.Tuesday && ToTime(Time[0]) >= 000000
            				|| Time[0].DayOfWeek == DayOfWeek.Wednesday && ToTime(Time[0]) >= 000000
            				|| Time[0].DayOfWeek == DayOfWeek.Thursday && ToTime(Time[0]) >= 000000
            				|| Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 180000)
            Let me know if I can be of further assistance.
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            144 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            70 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            125 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            78 views
            0 likes
            Last Post PaulMohn  
            Working...
            X