Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Seasonal filter: Trading day of month

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

    Seasonal filter: Trading day of month

    I have novice question related to seasonal filters. Basically, I would like to filter for certain trading days in the month. For instance, say I only wanted to trade specific trading (business) days of the month.

    So instead of Time[0].Day == 15 referencing the 15th day of the month, I would like it to reference the 15th trading day of the month.

    Where do I begin? Does anyone have a ready function for this?

    #2
    Hello don_janeiro,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    You would need a reference for the "trading days" in the month. Potentially, you could use a filter that filters out specific days of the week and times of the day and then count the number of days since the beginning of the month.

    Below is an indicator that would count the trading days of the month based on the CME US Index Futures ETH trading hours.
    Code:
        public class TradingDayOfTheMonth : Indicator
        {
            #region Variables
            private DateTime 	CurrentDate;
    		private int			count = 0;
            #endregion
    
            protected override void Initialize()
            {
                Overlay				= true;
            }
    
            protected override void OnBarUpdate()
            {
                if (Time[0].Month > CurrentDate.Month || Time[0].Year > CurrentDate.Year)
    			{
    				CurrentDate = Time[0];
    				count = 0;
    			}
    			if (((Time[0].DayOfWeek != DayOfWeek.Saturday || Time[0].DayOfWeek != DayOfWeek.Sunday)
    				&& ToTime(Time[0]) >= ToTime(17,0,0)
    				&& ToTime(Time[0]) <= ToTime(16,15,0))
    				||
    				Time[0].DayOfWeek == DayOfWeek.Sunday
    				&& ToTime(Time[0]) >= ToTime(17,0,0))
    			{
    				count++;
    			}
    			
    			if (count == 15)
    			{
    				// do something
    			}
    				
            }
        }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    51 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X