Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Contract rollover date
Collapse
X
-
Thanks for the code link Mathew, I'll give it a try!Originally posted by NinjaTrader_Matthew View PostThere is not a supported\documented method, but this information is readable from NinjaScript.
Please see the following indicator which uses some of the concepts:
http://www.ninjatrader.com/support/f...d=4&linkid=558
Comment
-
Howdy--
I fully understand that what I'm about to ask would be unsupported, however would it be plausible to think that using the exposed classes in the Rollover indicator (http://www.ninjatrader.com/support/f...ocal_links.php) that one might be able to surmise how to programmatically add expiries, rollover dates and offset values--as opposed to adding them manually via the Instrument Manger GUI?
Thanks,
Aventeren
Comment
-
Hello,
I have to state it but what you are asking would not be supported at all.
I am unsure if you could utilize the indicator in any manor to do what you are looking for, something you could look into is there is a file located in your install directory that holds instument information.
rollover dates are stored in this file so in theory edit this file and reset your instruments. As far if this will work correctly I do not know this would be something you could try. As long as you make a backup of the original file you should be able to reset this. the file would be db\Instruments.txt in your install directory.
Please let me know if i may be of additional assistance.
Comment
-
Thanks for pointing these out to me. This is exactly what I was looking for.Originally posted by NinjaTrader_Jesse View PostHello,
I have to state it but what you are asking would not be supported at all.
I am unsure if you could utilize the indicator in any manor to do what you are looking for, something you could look into is there is a file located in your install directory that holds instument information.
rollover dates are stored in this file so in theory edit this file and reset your instruments. As far if this will work correctly I do not know this would be something you could try. As long as you make a backup of the original file you should be able to reset this. the file would be db\Instruments.txt in your install directory.
Please let me know if i may be of additional assistance.
Any idea if there is a similar .txt file where the offsets are stored?
I clearly understand this whole exercise is unsupported, however I'll play around with adding new expiries (and hopefully offsets via another route) by amending the .txt file, and the I'll report back for the benefit of the other members.
Thanks for your help.
AventerenLast edited by aventeren; 09-18-2014, 08:29 AM.
Comment
-
Jesse--
I'm starting to poke around with changing the Instruments text file in the Program files (db folder), but I'm getting an "Access is Denied" message after I modify the file and try to re-save (I'm just adding a new "12-59, 19590825" expiry and rollover date to the ZW line per the formatting instructions in the file).
Any ideas?
Thanks,
Aventeren
Comment
-
Calculate Actual Contract Expiry Date
I wrote this code to get the actual contract expiry date. 7 days before the Triple Witching Hour this code switches to the next contract. It can be adapted according personal preferences:
This is the function to calculate the 3rd Friday of a month:Code:[FONT="Courier New"][SIZE="2"] // get the current contract // return 7 days before the rollover the next contract DateTime dtToday = DateTime.Now; int iYearBase = dtToday.Year; int iYearContract = iYearBase; int iMonthBase = dtToday.Month; int iMonthContract = ( ( iMonthBase - 1 ) / 3 ) * 3 + 3; DateTime dt3rdFriday = GetDateByOrdinalDay(iYearBase, iMonthContract, DayOfWeek.Friday, 3); if ( dt3rdFriday.Subtract(dtToday).TotalDays < 7 ) { // when the rollover date is in less than 7 days or it was already // --> switch to the next expiry date iMonthContract += 3; if ( iMonthContract > 12 ) { // we are in the next year iMonthContract = 3; iYearContract++; } } // iMonthContract has the month and iYearContract the year of the current future contract[/SIZE][/FONT]
Code:[FONT="Courier New"][SIZE="2"] /// <summary> /// returns the date of a x-th week day in a month. /// </summary> /// <param name="iYear">The year to calculate for</param> /// <param name="iMonth">The month to calculate for</param> /// <param name="dayOfWeek">The day of week to find</param> /// <param name="iOrdinal">The instance of the day of week to find</param> /// <returns>The resulting DateTime</returns> //------------------------------------------------------------------------------------------- public DateTime GetDateByOrdinalDay(int iYear, int iMonth, DayOfWeek dayOfWeek, int iOrdinal) //------------------------------------------------------------------------------------------- { DateTime Month1stDayOfWeek = new DateTime(iYear, iMonth, 1); // for negative ordinal it must be adjusted int iOrdinalAdjust = iOrdinal < 0 ? 1 : 0; // Convert Sunday explicitly to 7 int iMonth1stDayOfWeek = (Month1stDayOfWeek.DayOfWeek == DayOfWeek.Sunday) ? 7 : (int) Month1stDayOfWeek.DayOfWeek; // calculate the initial difference between the requested day and the 1st day of the month int iDayOffset = (int) dayOfWeek - iMonth1stDayOfWeek; // let the music play return Month1stDayOfWeek.AddDays ( iDayOffset + ( iOrdinal + iOrdinalAdjust - (iDayOffset < 0 ? 0 : 1) ) * 7 ); }[/SIZE][/FONT]Last edited by AlBundy; 04-10-2015, 04:13 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
639 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
572 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment