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 StockTrader88, 03-06-2021, 08:58 AM
    45 responses
    3,991 views
    3 likes
    Last Post johntraderuser2  
    Started by TAJTrades, Today, 09:46 AM
    0 responses
    6 views
    0 likes
    Last Post TAJTrades  
    Started by rhyminkevin, Yesterday, 04:58 PM
    5 responses
    62 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by realblubb, Today, 09:28 AM
    0 responses
    8 views
    0 likes
    Last Post realblubb  
    Started by AaronKoRn, Yesterday, 09:49 PM
    1 response
    19 views
    0 likes
    Last Post Rikazkhan007  
    Working...
    X