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

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 Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,788 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X