Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          21 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X