Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
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
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.
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....
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.
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...
In State.Configure (or DataLoaded) create an object with all the news events you want to heed (more on this below)
In OnBarUpdate, check if the current bar is within a defined window, and either:
So... how to create the list... Well, this is what I did.
Define a type that holds relevant data for the "High Volatility Period" or HVP in my code...
public struct HighVolPeriods
{
public string name;
public DateTime start_HV;
public DateTime end_HV;
}
Declare a List<T> object to hold a collection of HVP events
private List<HighVolPeriods> HVP = new List<HighVolPeriods>(); // list of periods of high vol... eg around announcements
Build your list, including whatever events you want, referring to the published schedule of announcements. My code looks like this:
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
}
Write something to check your List... this pretty much does it...call this in OBU
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;
}
One instance of my methods to add events...this code could probably be improved... I wrote it when I was a beginner!
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.
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.
if (State == State.Configure)
{
sessionIterator = new Data.SessionIterator(Bars);
}