NexusFi: Find Your Edge


Home Menu

 





Futures rollover webpage/stick thread


Discussion in Commodities

Updated
      Top Posters
    1. looks_one RM99 with 5 posts (0 thanks)
    2. looks_two TheDude with 2 posts (0 thanks)
    3. looks_3 baruchs with 2 posts (1 thanks)
    4. looks_4 Fat Tails with 2 posts (2 thanks)
    1. trending_up 6,604 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 12 posts
    2. attach_file 0 attachments




 
Search this Thread

Futures rollover webpage/stick thread

  #1 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704

I thought with all the brain horsepower on futures.io (formerly BMT), we could come up with a better resource for quick reference with respect to rollover dates.

I have an indicator (someone else wrote it) that gives me "days to rollover" that I run on my chart for CL. Now that I'm actually starting to venture out from CL, I found that a singular reference that has all the necessary information would be most helpful.

There are webpages like this Futures Expiration Dates

But it requires click and drop down etc.

Does anyone else think that a singular page that lists:

Current Symbol, expiration date, days to rollover

We could do this for various common instruments (CL, GC, NG, FDAX, NQ, ES, 6E, TF, YM, Brent, Silver, etc).

Obviously, some work would have to go into the coding, cause the number of days to rollover would be preferable in trading days (rather than calendar days) which also takes into account scheduled holidays for the particular exchage that hosts the instrument.

What are your thoughts?

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
76 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
37 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
17 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


The rollover question is simple for some of the futures contracts (including all the financials and precious metals) and it is difficult for physically traded commodities such as crude oil and the agriculturals.

I doubt that you can code an algorithm, which does it all.

Let us take CL. First you need to look up the last trade date and the first notice date. The rollover date needs to be prior to both these dates. Then the question is whether you use that rollover date

-> to roll your position (you will have a look at liquidity)
-> or to build a backadjusted contract (the offset depends on the rollover date)

For rolling my position, I will use some discretion, as for example that Cushing delivery is totally insane, so I would rather roll early than late, to avoid potential trouble during the last days of trading of that CL contract. I would be less concerned to roll a position late in Brent Crude traded at IPE.

I have never succeeded to find an algorithm for CL.

Reply With Quote
Thanked by:
  #4 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


Fat Tails View Post
The rollover question is simple for some of the futures contracts (including all the financials and precious metals) and it is difficult for physically traded commodities such as crude oil and the agriculturals.

I doubt that you can code an algorithm, which does it all.

Let us take CL. First you need to look up the last trade date and the first notice date. The rollover date needs to be prior to both these dates. Then the question is whether you use that rollover date

-> to roll your position (you will have a look at liquidity)
-> or to build a backadjusted contract (the offset depends on the rollover date)

For rolling my position, I will use some discretion, as for example that Cushing delivery is totally insane, so I would rather roll early than late, to avoid potential trouble during the last days of trading of that CL contract. I would be less concerned to roll a position late in Brent Crude traded at IPE.

I have never succeeded to find an algorithm for CL.

When I construct my custom contracts in CL, I have them roll 2 days prior to expiration (@CLV11=102XC). Waiting for volume superiority places you too close to trouble.

The sticky page or webpage wouldn't even have to be coded. It could simply be updated each day with number of days till rollover (or expiration) indicated.

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Started this thread Reply With Quote
  #5 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704

Here is a rollover indicator for CL futures. I'm in contact with the author (Dennis) on TS forums. I'll see if he has updated the suri function.
 
Code
// Indicator: dhDaysToExpiration 
// Dennis H: 2011 
// Plots the trading days to the expiration date or the first notice date, whichever comes first 
// Gives an alert AlertDays before expiration/first-notice 
// Uses the suri.isTradingDay function to find holidays and weekends 
 
Input:  
 AlertDays(2); 
 
Var: 
 ExpJDate(0), 
 ThisJDate(0), 
 DiffDays(0), 
 Count(0), 
 IntmdtDate(0), 
 DaysToExp(0); 
 
once begin 
 if FND > 0 then ExpJDate = DateToJulian(MinList(ExpDate, FND)) 
  else ExpJDate = DateToJulian(ExpDate); 
 ThisJDate = DateToJulian(Date); 
 DiffDays = ExpJDate - ThisJDate; 
 if DiffDays >= 1 then begin 
  for Count = 1 to DiffDays begin 
   IntmdtDate = JulianToDate(ExpJDate - Count); 
   if suri.isTradingDay(IntmdtDate) = 1 then DaysToExp = DaysToExp + 1; 
  end; 
 end; 
end; 
 
if Date > Date[1] then begin  
 ThisJDate = DateToJulian(Date); 
 DiffDays = ExpJDate - ThisJDate; 
 DaysToExp = 0; 
 if DiffDays >= 1 then begin 
  for Count = 1 to DiffDays begin 
   IntmdtDate = JulianToDate(ExpJDate - Count); 
   if suri.isTradingDay(IntmdtDate) = 1 then DaysToExp = DaysToExp + 1; 
  end; 
 end; 
end; 
  
Plot1(DaysToExp, "DaysToExp"); 
Plot2(0, "0"); 
 
if CheckAlert and DaysToExp <= AlertDays then Alert("Rollover Alert: " + SymbolRoot);

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Started this thread Reply With Quote
  #6 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704

Here is the suri function. It only includes holidays through 2011. The code is starting to get beyond my admitted capabilities. Maybe someone can modify/update it to include 2012, 2013, etc. (and still function properly).

 
Code
{
suri.isTradingDay
written by 
deMicron ("Suri Duddella")
Jan. 04, 2008
 suriNotes.com, suriNotes, Stock Research, Futures Trading, Emini Trading, Tradestation, Indicators
Returns: 0 for Holiday, 1 = Trading Day, 0.5 = EarlyClose/HalfDay, -1: Not in the DateList
Example:
 Day = suri.IsTradingDay(1080219);
 Day = suri.IsTradingDay(1051225);

1998 to 2007 Data Compiled from $INDU 5m Charts on TS.. Suri
2008, 2009 Data Manually compiled from NYSE Calendar .. Suri
}
//Input: checkDate(numericsimple), d1(numericSimple), d2(numericsimple);
Input: checkDate(numericsimple);
// Input: checkDate(numericsimple);
Arrays: HOLIDAYS[200,2](0);
Var: count(0), Found (0), hreturn(0), iStart(0), iEnd(0);
 
// 0 = Holiday, 1 = TradingDay, 0.5= HalfDay/EarlyClose ... 
// 1998
 HOLIDAYS[   1,1] =  980101; HOLIDAYS[   1,2] = 0;
 HOLIDAYS[   2,1] =  980119; HOLIDAYS[   2,2] = 0;
 HOLIDAYS[   3,1] =  980216; HOLIDAYS[   3,2] = 0;
 HOLIDAYS[   4,1] =  980410; HOLIDAYS[   4,2] = 0;
 HOLIDAYS[   5,1] =  980525; HOLIDAYS[   5,2] = 0;
 HOLIDAYS[   6,1] =  980703; HOLIDAYS[   6,2] = 0;
 HOLIDAYS[   7,1] =  980907; HOLIDAYS[   7,2] = 0;
 HOLIDAYS[   8,1] =  981126; HOLIDAYS[   8,2] = 0;
 HOLIDAYS[   9,1] =  981127; HOLIDAYS[   9,2] = 0.5;
 HOLIDAYS[  10,1] =  981224; HOLIDAYS[  10,2] = 0.5;
 HOLIDAYS[  11,1] =  981225; HOLIDAYS[  11,2] = 0;
// 1999
 HOLIDAYS[  12,1] =  990101; HOLIDAYS[  12,2] = 0;
 HOLIDAYS[  13,1] =  990118; HOLIDAYS[  13,2] = 0;
 HOLIDAYS[  14,1] =  990215; HOLIDAYS[  14,2] = 0;
 HOLIDAYS[  15,1] =  990402; HOLIDAYS[  15,2] = 0;
 HOLIDAYS[  16,1] =  990531; HOLIDAYS[  16,2] = 0;
 HOLIDAYS[  17,1] =  990705; HOLIDAYS[  17,2] = 0;
 HOLIDAYS[  18,1] =  990906; HOLIDAYS[  18,2] = 0;
 HOLIDAYS[  19,1] =  991125; HOLIDAYS[  19,2] = 0;
 HOLIDAYS[  20,1] =  991126; HOLIDAYS[  20,2] = 0.5;
 HOLIDAYS[  21,1] =  991224; HOLIDAYS[  21,2] = 0;
 HOLIDAYS[  22,1] =  991231; HOLIDAYS[  22,2] = 0.5;
 // 2000
 HOLIDAYS[  23,1] = 1000117; HOLIDAYS[  23,2] = 0;
 HOLIDAYS[  24,1] = 1000221; HOLIDAYS[  24,2] = 0;
 HOLIDAYS[  25,1] = 1000421; HOLIDAYS[  25,2] = 0;
 HOLIDAYS[  26,1] = 1000529; HOLIDAYS[  26,2] = 0;
 HOLIDAYS[  27,1] = 1000703; HOLIDAYS[  27,2] = 0.5;
 HOLIDAYS[  28,1] = 1000704; HOLIDAYS[  28,2] = 0;
 HOLIDAYS[  29,1] = 1000904; HOLIDAYS[  29,2] = 0;
 HOLIDAYS[  30,1] = 1001123; HOLIDAYS[  30,2] = 0;
 HOLIDAYS[  31,1] = 1001124; HOLIDAYS[  31,2] = 0.5;
 HOLIDAYS[  32,1] = 1001225; HOLIDAYS[  32,2] = 0;
 //2001
 HOLIDAYS[  33,1] = 1010101; HOLIDAYS[  33,2] = 0;
 HOLIDAYS[  34,1] = 1010115; HOLIDAYS[  34,2] = 0;
 HOLIDAYS[  35,1] = 1010219; HOLIDAYS[  35,2] = 0;
 HOLIDAYS[  36,1] = 1010413; HOLIDAYS[  36,2] = 0;
 HOLIDAYS[  37,1] = 1010528; HOLIDAYS[  37,2] = 0;
 HOLIDAYS[  38,1] = 1010703; HOLIDAYS[  38,2] = 0.5;
 HOLIDAYS[  39,1] = 1010704; HOLIDAYS[  39,2] = 0;
 HOLIDAYS[  40,1] = 1010903; HOLIDAYS[  40,2] = 0;
 HOLIDAYS[  41,1] = 1010911; HOLIDAYS[  41,2] = 0;  //Sept. 11
 HOLIDAYS[  42,1] = 1010912; HOLIDAYS[  42,2] = 0;
 HOLIDAYS[  43,1] = 1010913; HOLIDAYS[  43,2] = 0;
 HOLIDAYS[  44,1] = 1010914; HOLIDAYS[  44,2] = 0;
 HOLIDAYS[  45,1] = 1011122; HOLIDAYS[  45,2] = 0;
 HOLIDAYS[  46,1] = 1011123; HOLIDAYS[  46,2] = 0.5;
 HOLIDAYS[  47,1] = 1011224; HOLIDAYS[  47,2] = 0.5;
 HOLIDAYS[  48,1] = 1011225; HOLIDAYS[  48,2] = 0;
 //2002
 HOLIDAYS[  49,1] = 1020101; HOLIDAYS[  49,2] = 0;
 HOLIDAYS[  50,1] = 1020121; HOLIDAYS[  50,2] = 0;
 HOLIDAYS[  51,1] = 1020218; HOLIDAYS[  51,2] = 0;
 HOLIDAYS[  52,1] = 1020329; HOLIDAYS[  52,2] = 0;
 HOLIDAYS[  53,1] = 1020527; HOLIDAYS[  53,2] = 0;
 HOLIDAYS[  54,1] = 1020704; HOLIDAYS[  54,2] = 0;
 HOLIDAYS[  55,1] = 1020705; HOLIDAYS[  55,2] = 0.5;
 HOLIDAYS[  56,1] = 1020902; HOLIDAYS[  56,2] = 0;
 HOLIDAYS[  57,1] = 1021128; HOLIDAYS[  57,2] = 0;
 HOLIDAYS[  58,1] = 1021129; HOLIDAYS[  58,2] = 0.5;
 HOLIDAYS[  59,1] = 1021224; HOLIDAYS[  59,2] = 0.5;
 HOLIDAYS[  60,1] = 1021225; HOLIDAYS[  60,2] = 0;
 //2003
 HOLIDAYS[  61,1] = 1030101; HOLIDAYS[  61,2] = 0;
 HOLIDAYS[  62,1] = 1030120; HOLIDAYS[  62,2] = 0;
 HOLIDAYS[  63,1] = 1030217; HOLIDAYS[  63,2] = 0;
 HOLIDAYS[  64,1] = 1030418; HOLIDAYS[  64,2] = 0;
 HOLIDAYS[  65,1] = 1030526; HOLIDAYS[  65,2] = 0;
 HOLIDAYS[  66,1] = 1030703; HOLIDAYS[  66,2] = 0.5;
 HOLIDAYS[  67,1] = 1030704; HOLIDAYS[  67,2] = 0;
 HOLIDAYS[  68,1] = 1030901; HOLIDAYS[  68,2] = 0;
 HOLIDAYS[  69,1] = 1031127; HOLIDAYS[  69,2] = 0;
 HOLIDAYS[  70,1] = 1031128; HOLIDAYS[  70,2] = 0.5;
 HOLIDAYS[  71,1] = 1031224; HOLIDAYS[  71,2] = 0.5;
 HOLIDAYS[  72,1] = 1031225; HOLIDAYS[  72,2] = 0;
 HOLIDAYS[  73,1] = 1031226; HOLIDAYS[  73,2] = 0.5;
 //2004
 HOLIDAYS[  74,1] = 1040101; HOLIDAYS[  74,2] = 0;
 HOLIDAYS[  75,1] = 1040119; HOLIDAYS[  75,2] = 0;
 HOLIDAYS[  76,1] = 1040216; HOLIDAYS[  76,2] = 0;
 HOLIDAYS[  77,1] = 1040409; HOLIDAYS[  77,2] = 0;
 HOLIDAYS[  78,1] = 1040531; HOLIDAYS[  78,2] = 0;
 HOLIDAYS[  79,1] = 1040611; HOLIDAYS[  79,2] = 0; // Ronald Reagan's
 HOLIDAYS[  80,1] = 1040705; HOLIDAYS[  80,2] = 0;
 HOLIDAYS[  81,1] = 1040906; HOLIDAYS[  81,2] = 0;
 HOLIDAYS[  82,1] = 1041125; HOLIDAYS[  82,2] = 0;
 HOLIDAYS[  83,1] = 1041126; HOLIDAYS[  83,2] = 0.5;
 HOLIDAYS[  84,1] = 1041224; HOLIDAYS[  84,2] = 0;
 //2005
 HOLIDAYS[  85,1] = 1050117; HOLIDAYS[  85,2] = 0;
 HOLIDAYS[  86,1] = 1050221; HOLIDAYS[  86,2] = 0;
 HOLIDAYS[  87,1] = 1050325; HOLIDAYS[  87,2] = 0;
 HOLIDAYS[  88,1] = 1050530; HOLIDAYS[  88,2] = 0;
 HOLIDAYS[  89,1] = 1050704; HOLIDAYS[  89,2] = 0;
 HOLIDAYS[  90,1] = 1050905; HOLIDAYS[  90,2] = 0;
 HOLIDAYS[  91,1] = 1051124; HOLIDAYS[  91,2] = 0;
 HOLIDAYS[  92,1] = 1051125; HOLIDAYS[  92,2] = 0.5;
 HOLIDAYS[  93,1] = 1051226; HOLIDAYS[  93,2] = 0;
 //2006
 HOLIDAYS[  94,1] = 1060102; HOLIDAYS[  94,2] = 0;
 HOLIDAYS[  95,1] = 1060116; HOLIDAYS[  95,2] = 0;
 HOLIDAYS[  96,1] = 1060220; HOLIDAYS[  96,2] = 0;
 HOLIDAYS[  97,1] = 1060414; HOLIDAYS[  97,2] = 0;
 HOLIDAYS[  98,1] = 1060529; HOLIDAYS[  98,2] = 0;
 HOLIDAYS[  99,1] = 1060703; HOLIDAYS[  99,2] = 0.5;
 HOLIDAYS[ 100,1] = 1060704; HOLIDAYS[ 100,2] = 0;
 HOLIDAYS[ 101,1] = 1060904; HOLIDAYS[ 101,2] = 0;
 HOLIDAYS[ 102,1] = 1061123; HOLIDAYS[ 102,2] = 0;
 HOLIDAYS[ 103,1] = 1061124; HOLIDAYS[ 103,2] = 0.5;
 HOLIDAYS[ 104,1] = 1061225; HOLIDAYS[ 104,2] = 0;
 //2007
 HOLIDAYS[ 105,1] = 1070101; HOLIDAYS[ 105,2] = 0;
 HOLIDAYS[ 106,1] = 1070102; HOLIDAYS[ 106,2] = 0; // Gerald Ford's
 HOLIDAYS[ 107,1] = 1070105; HOLIDAYS[ 107,2] = 0;
 HOLIDAYS[ 108,1] = 1070115; HOLIDAYS[ 108,2] = 0;
 HOLIDAYS[ 109,1] = 1070219; HOLIDAYS[ 109,2] = 0;
 HOLIDAYS[ 110,1] = 1070406; HOLIDAYS[ 110,2] = 0;
 HOLIDAYS[ 111,1] = 1070528; HOLIDAYS[ 111,2] = 0;
 HOLIDAYS[ 112,1] = 1070703; HOLIDAYS[ 112,2] = 0.5;
 HOLIDAYS[ 113,1] = 1070704; HOLIDAYS[ 113,2] = 0;
 HOLIDAYS[ 114,1] = 1070903; HOLIDAYS[ 114,2] = 0;
 HOLIDAYS[ 115,1] = 1071122; HOLIDAYS[ 115,2] = 0;
 HOLIDAYS[ 116,1] = 1071123; HOLIDAYS[ 116,2] = 0.5;
 HOLIDAYS[ 117,1] = 1071224; HOLIDAYS[ 117,2] = 0.5;
 HOLIDAYS[ 118,1] = 1071225; HOLIDAYS[ 118,2] = 0;
 // Manual Entries for 2008, 2009 Holidays from NYSE Calendar... Suri
 // 2008
 HOLIDAYS[ 119,1] = 1080101; HOLIDAYS[ 119,2] = 0;
 HOLIDAYS[ 120,1] = 1080121; HOLIDAYS[ 120,2] = 0;
 HOLIDAYS[ 121,1] = 1080218; HOLIDAYS[ 121,2] = 0;
 HOLIDAYS[ 122,1] = 1080321; HOLIDAYS[ 122,2] = 0;
 HOLIDAYS[ 123,1] = 1080526; HOLIDAYS[ 123,2] = 0;
 HOLIDAYS[ 124,1] = 1080703; HOLIDAYS[ 124,2] = 0.5;
 HOLIDAYS[ 125,1] = 1080704; HOLIDAYS[ 125,2] = 0;
 HOLIDAYS[ 126,1] = 1080901; HOLIDAYS[ 126,2] = 0;
 HOLIDAYS[ 127,1] = 1081127; HOLIDAYS[ 127,2] = 0;
 HOLIDAYS[ 128,1] = 1081127; HOLIDAYS[ 128,2] = 0;
 HOLIDAYS[ 129,1] = 1081128; HOLIDAYS[ 129,2] = 0.5;
 HOLIDAYS[ 130,1] = 1081224; HOLIDAYS[ 130,2] = 0.5;
 HOLIDAYS[ 131,1] = 1081225; HOLIDAYS[ 131,2] = 0;
// 2009
 HOLIDAYS[ 132,1] = 1090101; HOLIDAYS[ 132,2] = 0;
 HOLIDAYS[ 133,1] = 1090119; HOLIDAYS[ 133,2] = 0;
 HOLIDAYS[ 134,1] = 1090216; HOLIDAYS[ 134,2] = 0;
 HOLIDAYS[ 135,1] = 1090410; HOLIDAYS[ 135,2] = 0;
 HOLIDAYS[ 136,1] = 1090525; HOLIDAYS[ 136,2] = 0;
 HOLIDAYS[ 137,1] = 1090703; HOLIDAYS[ 137,2] = 0;
 HOLIDAYS[ 138,1] = 1090907; HOLIDAYS[ 138,2] = 0;
 HOLIDAYS[ 139,1] = 1091126; HOLIDAYS[ 139,2] = 0;
 HOLIDAYS[ 140,1] = 1091127; HOLIDAYS[ 140,2] = 0.5;
 HOLIDAYS[ 141,1] = 1091224; HOLIDAYS[ 141,2] = 0.5;
 HOLIDAYS[ 142,1] = 1091225; HOLIDAYS[ 142,2] = 0;
 
 // 2010
 HOLIDAYS[ 143,1] = 1100101; HOLIDAYS[ 143,2] = 0;
 HOLIDAYS[ 144,1] = 1100118; HOLIDAYS[ 144,2] = 0;
 HOLIDAYS[ 145,1] = 1100215; HOLIDAYS[ 145,2] = 0;
 HOLIDAYS[ 146,1] = 1100402; HOLIDAYS[ 146,2] = 0;
 HOLIDAYS[ 147,1] = 1100531; HOLIDAYS[ 147,2] = 0;
 HOLIDAYS[ 148,1] = 1100705; HOLIDAYS[ 148,2] = 0;
 HOLIDAYS[ 149,1] = 1100906; HOLIDAYS[ 149,2] = 0;
 HOLIDAYS[ 150,1] = 1101125; HOLIDAYS[ 150,2] = 0;
 HOLIDAYS[ 151,1] = 1101126; HOLIDAYS[ 151,2] = 0.5;
 HOLIDAYS[ 152,1] = 1101224; HOLIDAYS[ 152,2] = 0;
  // 2011
 HOLIDAYS[ 153,1] = 1110117; HOLIDAYS[ 153,2] = 0;
 HOLIDAYS[ 154,1] = 1110221; HOLIDAYS[ 154,2] = 0;
 HOLIDAYS[ 155,1] = 1110422; HOLIDAYS[ 155,2] = 0;
 HOLIDAYS[ 156,1] = 1110530; HOLIDAYS[ 156,2] = 0;
 HOLIDAYS[ 157,1] = 1110704; HOLIDAYS[ 157,2] = 0;
 HOLIDAYS[ 158,1] = 1110905; HOLIDAYS[ 158,2] = 0;
 HOLIDAYS[ 159,1] = 1111124; HOLIDAYS[ 159,2] = 0;
 HOLIDAYS[ 160,1] = 1111125; HOLIDAYS[ 160,2] = 0.5;
 HOLIDAYS[ 161,1] = 1111226; HOLIDAYS[ 161,2] = 0;
 
 
 if checkDate >= 980101 and checkDate <= 981231 then
 begin
  iStart = 1;
 iEnd = 11;
 end
 else if checkDate >= 990101 and checkDate <= 991231 then
 begin
  iStart = 12;
 iEnd = 22;
 end  else if checkDate >= 1000101 and checkDate <= 1001231 then
 begin
  iStart = 23;
 iEnd = 32;
 end  else if checkDate >= 1010101 and checkDate <= 1011231 then
 begin
  iStart = 33;
 iEnd = 48;
 end   else if checkDate >= 1020101 and checkDate <= 1021231 then
 begin
  iStart = 49;
 iEnd = 60;
 end  else if checkDate >= 1030101 and checkDate <= 1031231 then
 begin
  iStart = 61;
 iEnd = 73;
 end  else if checkDate >= 1040101 and checkDate <= 1041231 then
 begin
  iStart = 74;
 iEnd = 84;
 end  else if checkDate >= 1050101 and checkDate <= 1051231 then
 begin
  iStart = 85;
 iEnd = 93;
 end  else if checkDate >= 1060101 and checkDate <= 1061231 then
 begin
  iStart = 94;
 iEnd = 104;
 end  else if checkDate >= 1070101 and checkDate <= 1071231 then
 begin
  iStart = 105;
 iEnd = 118;
 end  else if checkDate >= 1080101 and checkDate <= 1081231 then
 begin
  iStart = 119;
 iEnd = 131;
 end   else if checkDate >= 1090101 and checkDate <= 1091231 then
 begin
  iStart = 132;
 iEnd = 142;
 end   else if checkDate >= 1100101 and checkDate <= 1101231 then
 begin
  iStart = 143;
 iEnd = 152;
 end   else if checkDate >= 1110101 and checkDate <= 1111231 then
 begin
  iStart = 153;
 iEnd = 161;
 end

 else  // Out of the range of this DB...
 begin
  iStart = 0;
 iEnd = 0;
 Found = -100;
 hreturn = -1;  // Not In DB 
 end;
  
 
if ((DayOfWeek(checkDate) = 0) OR (DayOfWeek(checkDate) = 6)) then  // Saturady or Sunday
begin
 hreturn = 0;   // Saturday, Sunday... 
end
else if (iStart > 0 and iEnd > 0) then
begin
 Found=-1;  
 for count= iStart to iEnd
 begin
  value10 = IntPortion(Holidays[count,1]);
  if (value10 = Intportion(checkDate)) then
  begin  
   Found =1;  
   hreturn = HOLIDAYS[count,2];
   count=10000; // Short-Circuit
  end;
 end;
 if (Found =-1) then  // Not a Holiday
  hreturn = 1; // Full-Trading Day
end;
suri.isTradingDay = hreturn; 
 

// print("TestD  = ", checkDate, " DayofWeek  = ", DayOfWeek(checkDate));   
// print("Count = ", count, "HC = ", Holidays[count,1]);    
// print("Found = ", " Count = ", Count);   
// print("hreturn = ", hreturn);
// print("Istart = ", istart, " iEnd = ", Iend);

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Started this thread Reply With Quote
  #7 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

Hey,
I think that it is a great idea to have functions for both rollovers and holidays.
I'm interested in coding this for NT.
As a rule I don't code indicators, only if its necessary for my strategies, but I think first we need to agree on functions that can be called from any indicator. After we'll have those functions anyone will be able to code his own indicator that meets his/her needs.
The way to do it I think is by creating "csv" file.
For holidays I propose this format:
1. Exchange/Instrument - "All" for all instruments.
2. Date in format YYYYMMDD
3. Close time in format HHMM. "Zero" for full holiday.

For rollovers we need two files.
File 1:
1. Instrument/Instrument category (indexes, currencies, CL...)
2. Last trade date YYYYMMDD
3. First notice date YYYYMMDD
4. Contract month MMDD

File 2:
1. Instrument/Instrument category (indexes, currencies, CL...)
2. Rollover advance in days. ##

Instrument which doesn't need the rollover file will be calculated inside the function. Still they can exist in file 2.
That way each trader will be able to tweak it for his/her personal preferences.

Tell me what you think.

Baruch
p.s. All times will be in ET.

Reply With Quote
  #8 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
Posts: 839 since Mar 2011
Thanks Given: 124
Thanks Received: 704


baruchs View Post
Hey,
I think that it is a great idea to have functions for both rollovers and holidays.
I'm interested in coding this for NT.
As a rule I don't code indicators, only if its necessary for my strategies, but I think first we need to agree on functions that can be called from any indicator. After we'll have those functions anyone will be able to code his own indicator that meets his/her needs.
The way to do it I think is by creating "csv" file.
For holidays I propose this format:
1. Exchange/Instrument - "All" for all instruments.
2. Date in format YYYYMMDD
3. Close time in format HHMM. "Zero" for full holiday.

For rollovers we need two files.
File 1:
1. Instrument/Instrument category (indexes, currencies, CL...)
2. Last trade date YYYYMMDD
3. First notice date YYYYMMDD
4. Contract month MMDD

File 2:
1. Instrument/Instrument category (indexes, currencies, CL...)
2. Rollover advance in days. ##

Instrument which doesn't need the rollover file will be calculated inside the function. Still they can exist in file 2.
That way each trader will be able to tweak it for his/her personal preferences.

Tell me what you think.

Baruch
p.s. All times will be in ET.

To be honest with you, I'm a mile wide and an inch deep when it comes to coding. I know enough to accomplish many of the things that I need and only some of the things I would like.

The code above works, how it translates to C, is beyond me. But like I said, I have to get in touch with the author and see if he has an updated version of the suri function that has the holiday schedule out past the end of this year.

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Started this thread Reply With Quote
  #9 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


Quoting 
To be honest with you, I'm a mile wide and an inch deep when it comes to coding. I know enough to accomplish many of the things that I need and only some of the things I would like.

The code above works, how it translates to C, is beyond me. But like I said, I have to get in touch with the author and see if he has an updated version of the suri function that has the holiday schedule out past the end of this year.

No offense, but my proposal was not for you. It is for a small community of Ninja traders on this forum.

Baruch

Reply With Quote
  #10 (permalink)
 dloomis514 
NORTH ATTLEBORO
 
Experience: Intermediate
Platform: nt
Trading: 02760
Posts: 12 since Aug 2011
Thanks Given: 4
Thanks Received: 7


if you can follow the logic, this works for the ES in eSignal, determines the next expiry date, the thursday the week before the third friday of mar jun sep and dec, year independent.

var Third_Friday = exp = null; var YY = DD = MM = expY = expT = 0;

function preMain() {
setPriceStudy(true);
setStudyTitle("ExpCalc");
debugClear();
}

function main() {
//if(getBarState() == BARSTATE_ALLBARS)return
if ( getBarState() == BARSTATE_NEWBAR && getMinute() == 30 && getHour() == 16) {
expY = expT*1;
YY = year(0); MM = month(0); DD = day(0);
Month=(Math.floor((MM-0.1)/3)+1)*3; //0-11 ==> 3, 6, 9 or 12
get_expiry_date(Month, YY); //basic logic to find Rollover Thursday
if ( DD > Third_Friday && MM == Month ){ //after expiry in Mar Jun and Sept
MM = Month + 3;
get_expiry_date(MM, YY);
}
else MM = Month;
if ( MM <= 9 ) MM = "0" + MM;
if ( MM >= 13 ) { MM = "03" ; YY = YY + 1 ; }//next March, next year
debugPrintln(" "+month(0)+" "+(DD*1-1)+" "+MM+" "+Third_Friday)
exp = YY + "" + MM ;
expT = MM*1000000+Third_Friday*10000+YY*1
if (expT != expY && expY != 0 ) {
debugPrintln( month(0)+"/"+day(0)+"/"+year(0)+" "+expY+" "+expT+" "+open(0, inv("D"))+" "+close(-1, inv("D"))+" "+MM+"/"+Third_Friday)
}
}
return //expT/1+""
}

function get_expiry_date( Month, YY ) {
First_day_of_Month = new Date( YY, Month-1, 1 );//month is 0-11,
Weekday = First_day_of_Month.getDay(); //getDay() is 0 - 6, sunday = 0
//debugPrintln(Weekday*1+" "+(Month)) //ok
//debugPrintln(month(0)+" "+YY+" "+Month+" "+Weekday)
if ( 5 - Weekday >= 0 ) Third_Friday = 20 - Weekday - 9;
else Third_Friday = 21 - 9;
return Third_Friday;}

Reply With Quote




Last Updated on September 12, 2013


© 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