NexusFi: Find Your Edge


Home Menu

 





holiday and reports sample strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one tgntrader with 2 posts (0 thanks)
    2. looks_two sg72 with 2 posts (0 thanks)
    3. looks_3 Jasonnator with 2 posts (1 thanks)
    4. looks_4 Ssjaznguy with 1 posts (1 thanks)
    1. trending_up 1,699 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

holiday and reports sample strategy

  #1 (permalink)
 Ssjaznguy 
la puente, California
 
Experience: None
Platform: NinjaTrader
Trading: Es
Posts: 30 since Oct 2018
Thanks Given: 7
Thanks Received: 1

Hi,

I had a virus that forced me to reinstall my OS and need to recode my strategy. Can someone please send me a sample strategy that I can use to halt trading during holidays or high impact US news reports

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
24 thanks
Diary of a simple price action trader
21 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
9 thanks
  #2 (permalink)
tgntrader
Adelaide, S.A., Australia
 
Posts: 4 since Jan 2013
Thanks Given: 0
Thanks Received: 0

XABCD Trading have an excellent news indicator for news events... and it's free. Recommend you look at that, I am sure you will find it covers what you want.

Can't post the link... look at www dot xabcdtrading dot com/membership-details/news-indicator-ninjatrader-nt8

Cheers,

Reply With Quote
  #3 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
Posts: 59 since Sep 2018
Thanks Given: 44
Thanks Received: 48


I haven't looked at high impact US news reports, but I have a code snippet that I use in my indicators when I need to know if it's a holiday or half day. Can't send you the whole thing, but I've attached the relevant parts for your reference to detect holidays and half days. You'll have to change the Trading Hours value to whichever you wish.

Hope this helps.

 
Code
		Data.SessionIterator sessionIterator;
		
		TradingHours rth_hours = TradingHours.Get("US Equities RTH") ;
		string session_date ;
		bool session_is_holiday	= true ;
		bool session_is_halfday	= true ;

		protected override void OnBarUpdate()
		{
			if( !Bars.BarsType.IsTimeBased ) return ;

			if( Bars.IsFirstBarOfSession )
			{
				session_is_holiday = false ;
				session_is_halfday = false ;
				session_date = sessionIterator.GetTradingDay(Time[0]).ToString("yyyyMMdd") ;
				
				foreach(KeyValuePair<DateTime, string> holiday in rth_hours.Holidays)
				{
					if( holiday.Key.ToString("yyyyMMdd") == session_date )
					{
						session_is_holiday = true ;
					}
				}

				if( ! session_is_holiday )
				{
					foreach(KeyValuePair<DateTime, PartialHoliday> holiday in rth_hours.PartialHolidays)
					{
						if( holiday.Key.ToString("yyyyMMdd") == session_date )
						{
							session_is_halfday = true ;
						}
					}
				}
			}

			[ the rest of your code ... ]
		}

Reply With Quote
  #4 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166

I can offer some help for the holiday portion of your question. There are 2 built in properties which NT8 offers which sound like exactly what would help you. Full holidays and partial holidays which are updated very easy by the built in templates (from memory, I think it's in the DB dialog window). I check exactly this in some strategies using the SessionIterator and even made a video on how to use that mechanism. Hopefully that helps on the holiday portion of your question. I wish I had something for specific news events as well. Maybe I'll add that to my list of stuff to make next....

How I develop my trading tools: How to videos
Latest: Trading hours and Mid price

Free code: GitLab repository
Reply With Quote
  #5 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166


sg72 View Post
I haven't looked at high impact US news reports, but I have a code snippet that I use in my indicators when I need to know if it's a holiday or half day. Can't send you the whole thing, but I've attached the relevant parts for your reference to detect holidays and half days. You'll have to change the Trading Hours value to whichever you wish.

Hope this helps.

 
Code
		Data.SessionIterator sessionIterator;
		
		TradingHours rth_hours = TradingHours.Get("US Equities RTH") ;
		string session_date ;
		bool session_is_holiday	= true ;
		bool session_is_halfday	= true ;

		protected override void OnBarUpdate()
		{
			if( !Bars.BarsType.IsTimeBased ) return ;

			if( Bars.IsFirstBarOfSession )
			{
				session_is_holiday = false ;
				session_is_halfday = false ;
				session_date = sessionIterator.GetTradingDay(Time[0]).ToString("yyyyMMdd") ;
				
				foreach(KeyValuePair<DateTime, string> holiday in rth_hours.Holidays)
				{
					if( holiday.Key.ToString("yyyyMMdd") == session_date )
					{
						session_is_holiday = true ;
					}
				}

				if( ! session_is_holiday )
				{
					foreach(KeyValuePair<DateTime, PartialHoliday> holiday in rth_hours.PartialHolidays)
					{
						if( holiday.Key.ToString("yyyyMMdd") == session_date )
						{
							session_is_halfday = true ;
						}
					}
				}
			}

			[ the rest of your code ... ]
		}

@sg72,

Do you ever run into issues instantiating your session iterator as a field? I'm just curious because I've had an issue before and had to put it in the DataLoaded state of OnStateChange.

How I develop my trading tools: How to videos
Latest: Trading hours and Mid price

Free code: GitLab repository
Reply With Quote
Thanked by:
  #6 (permalink)
tgntrader
Adelaide, S.A., Australia
 
Posts: 4 since Jan 2013
Thanks Given: 0
Thanks Received: 0

OK, I see my reference to XABCD doesn't really cut it if you want to automate things, but is pretty cool if you want a visual warning of approaching news events

I have written strategies that modify behaviour during various announcement periods... I won't show the entire code, but I can point you on how to achieve what you want...
  1. In State.Configure (or DataLoaded) create an object with all the news events you want to heed (more on this below)
  2. In OnBarUpdate, check if the current bar is within a defined window, and either:
    1. Abort ... ie prevent trading, or
    2. Modify trading parameters, eg, tighten stops, change dependent indicator settings etc

So... how to create the list... Well, this is what I did.
  1. Define a type that holds relevant data for the "High Volatility Period" or HVP in my code...
     
    Code
           public struct HighVolPeriods
            {
                public string name;
                public DateTime start_HV;
                public DateTime end_HV;
            }
  2. Declare a List<T> object to hold a collection of HVP events
     
    Code
            private List<HighVolPeriods> HVP = new List<HighVolPeriods>();  // list of periods of high vol... eg around announcements
  3. Build your list, including whatever events you want, referring to the published schedule of announcements. My code looks like this:
     
    Code
            private void Load_HVP()
            {
    // NOTE: Times below are LOCAL... not ET
                if (Announce_Crude)     Weekly_Announcement("Crude", DayOfWeek.Wednesday, 0, 0, HVmins);
                if (Announce_Jobless)   Weekly_Announcement("Jobless Claims", DayOfWeek.Thursday, 22, 0, HVmins);
                if (Announce_ISM_Man)   Monthly_Announcement("ISM Manufacturing (PMI)", 1, 23, 30, HVmins);
                if (Announce_ISM_NonMan) Monthly_Announcement("ISM Non-Manufacturing", 3, 23, 30, HVmins);      // 3rd business day of month
    // FOMC is tricky - released 8 times a year... too hard for now
    // if (Announce_FOMC) Monthly_Announcement("FOMC", 1, 23, 30, HVmins);
    // NFP, or "Employment Situation, is released 8:30 AM ET, first Friday of the month
                if (Announce_NFP) Monthly_Announcement_DOW("Non-Farm Payroll", DayOfWeek.Friday, 1, 22, 0, HVmins); 
    //            if (Announce_CPI) Monthly_Announcement("CPI", 1, 22, 0, HVmins);                        // CPI 8:30 AM ET, but day varies.. too hard for now
            }
  1. Write something to check your List... this pretty much does it...call this in OBU
     
    Code
            private bool Check_High_Volatility(DateTime bartime)
            {
                bool found = false;
                int i;
    
                i = 0;
                while (i < HVP.Count && !found)
                {
                    found = DateTime.Compare(HVP[i].start_HV, bartime) <= 0 && DateTime.Compare(HVP[i].end_HV, bartime) >= 0;
                    i++;
                }
                return found;
           }
  1. One instance of my methods to add events...this code could probably be improved... I wrote it when I was a beginner!
     
    Code
            private void Monthly_Announcement(string name, int dom, int hr, int mins, int hv_duration)
            {
                int y, m;
                DateTime t1, seriesstartdate;
                DateTime begin_date;           // bit more tricky than weeklies...
                HighVolPeriods HVPinst = new HighVolPeriods();
                HighVolPeriods HVPnew;
    
                y = DateTime.Now.Year;
                m = DateTime.Now.Month;
                begin_date = new DateTime(y, m, dom, hr, mins, 0);     // get first instance
                t1 = begin_date;
                while (t1.DayOfWeek == DayOfWeek.Saturday || t1.DayOfWeek == DayOfWeek.Sunday)
                    t1 = t1.AddDays(1);
    // should now be a weekday.  Ignore holidays for now...
    
                HVPinst.name = name;
                HVPinst.start_HV = t1;
                HVPinst.end_HV = t1.AddMinutes(hv_duration);
    
                HVPnew = HVPinst;
                HVP.Add(HVPnew);
    
                seriesstartdate = Bars.GetTime(0);
                // now work backwards to start of chart/series...
                while (DateTime.Compare(seriesstartdate, HVPnew.start_HV) < 0)
                {
                    begin_date = begin_date.AddMonths(-1);
                    t1 = begin_date;
                    while (t1.DayOfWeek == DayOfWeek.Saturday || t1.DayOfWeek == DayOfWeek.Sunday)
                        t1 = t1.AddDays(1);
    
                    HVPinst.start_HV = t1;
                    HVPinst.end_HV = t1.AddMinutes(hv_duration);
                    HVPnew = HVPinst;
                    HVP.Add(HVPnew);
                }
            }
Now... caveats:
  • I live in Australia, so timezone is way different to US, beware of this issue unless you reside somewhere that uses ET or whatever.
  • I did not at the time deal with holidays... the posts from others could be used to include this.
  • I used a parameter hv_duration.. which enabled me to optimise the strategy choosing variable length "blackout periods"... Use if you want...
  • Apologies if you don't like my code... like I said, I wrote this stuff a while back when was pretty new to C# coding, it is probably not real elegant...
  • You will want a "weeklies" method as well... not shown... but you should have the concept. If you really need more help, let me know, I can post my version of that also. For now, regard it as your homework to write it yourself ;-)

Hope that solves the issue for news announcements... the other stuff re holidays from others looks just fine.

Cheers, from Down Under!

Reply With Quote
  #7 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
Posts: 59 since Sep 2018
Thanks Given: 44
Thanks Received: 48


Jasonnator View Post
@sg72,

Do you ever run into issues instantiating your session iterator as a field? I'm just curious because I've had an issue before and had to put it in the DataLoaded state of OnStateChange.


You're right. I guess I forgot to include that part of the code. Good catch.

I declare the variable sessionIterator before OnStateChange(). But I instantiate it inside State.Configure.

 
Code
			if (State == State.Configure)
			{
				sessionIterator = new Data.SessionIterator(Bars);
			}

Reply With Quote




Last Updated on June 7, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts