Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to check for a day in a month like triple witching day?

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

    How to check for a day in a month like triple witching day?

    Hi,

    I have been hard-coding the triple-witching days in my code. But there must be a way check via code if today is third friday of March/June/Spetember/December. If you could share a code for that, it would help me.

    thanks

    #2
    Hello vishalct,

    Thank you for your post.

    Code:
    			if(Time[0].Day > Time[1].Day
    				&& Time[0].Month == Time[1].Month
    				&& Time[0].DayOfWeek == DayOfWeek.Friday)
    			{
    				fCount++;
    			}
    			else if(Time[0].Month != Time[1].Month)
    			{
    				fCount = 0;
    			}
    			
    			if(fCount == 3
    				&& (Time[0].Month == 3
    				|| Time[0].Month == 6
    				|| Time[0].Month == 9
    				|| Time[0].Month == 12))
    			{
    				// do something
    			}
    Where fCount is an int declared in the Variables region.
    For information on DateTime please visit the following link: https://msdn.microsoft.com/en-us/lib....datetime.aspx
    Last edited by NinjaTrader_PatrickH; 09-18-2015, 12:32 PM.

    Comment


      #3
      You'll need some custom code on that one.

      Asking Google how to find the 3rd Friday in .net returns alot of suggestions.


      Here's one such discussion:

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello vishalct,

        Thank you for your post.

        Code:
        			if(Time[0].Day > Time[1].Day
        				&& Time[0].Month == Time[1].Month
        				&& Time[0].DayOfWeek == DayOfWeek.Friday)
        			{
        				fCount++;
        			}
        			else if(Time[0].Month != Time[1].Month)
        			{
        				fCount = 0;
        			}
        			
        			if(fCount = 3
        				&& (Time[0].Month == 3
        				|| Time[0].Month == 6
        				|| Time[0].Month == 9
        				|| Time[0].Month == 12))
        			{
        				// do something
        			}
        Where fCount is an int declared in the Variables region.
        For information on DateTime please visit the following link: https://msdn.microsoft.com/en-us/lib....datetime.aspx
        Slight correction.
        Code:
        if(fCount == 3 ...
        Comparison, not assignment.

        Comment


          #5
          Reviewing my code after correcting my error I realize this would miss the first Friday if it was the first of month. While rare, it can occur. You would make the changes I made below in Bold.

          Code:
          			if(Time[0].Day > Time[1].Day
          				&& Time[0].Month == Time[1].Month
          				&& Time[0].DayOfWeek == DayOfWeek.Friday)
          			{
          				fCount++;
          			}
          			[B]else if(Time[0].Month != Time[1].Month
          				&& Time[0].DayOfWeek == DayOfWeek.Friday
          				&& Time[0].Day == 1)
          			{
          				fCount = 1;
          			}
          			else
          			{
          				fCount = 0;
          			}[/B]
          			
          			if(fCount == 3
          				&& (Time[0].Month == 3
          				|| Time[0].Month == 6
          				|| Time[0].Month == 9
          				|| Time[0].Month == 12))
          			{
          				// do something
          			}

          Comment

          Latest Posts

          Collapse

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