As you can see in Crude oil contract the last trading day is changing every month and we don't have the constant date for it.
How to identify the last trading days of each contracts that includes in continuous contract?
Continuous contract have a lot of contracts linked within and I need to find out all dates of the joints.
How to identify place where linked contracts in continuous contract? [SOLVED]
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2228 times
Re: How to identify place where linked contracts in continuous contract?
Are you aware that most traders skip a contract month with crude oil?
Re: How to identify place where linked contracts in continuous contract?
Excuse me, but I don't understand your question quiet well. My question was about identifying places where continuous contract was linkedAre you aware that most traders skip a contract month with crude oil?
Re: How to identify place where linked contracts in continuous contract?
I have answer from IQfeed, they can not help with this, because they do not store expiration dates and can not help with identification of it.
But if we can't identify this dates - the back tests is not so correct. Because in real trading you have to close all your position before expiration and you can not emulate this with back tests. And backtest results can be better or worse than real time trading.
But if we can't identify this dates - the back tests is not so correct. Because in real trading you have to close all your position before expiration and you can not emulate this with back tests. And backtest results can be better or worse than real time trading.
Re: How to identify place where linked contracts in continuous contract?
from CME website link provided earlier and it states following
"Trading terminates 3 business day prior to the 25th calendar day of the month prior to the contract month. If the 25th calendar day is not a business day, trading terminates 4 business days prior to the 25th calendar day of the month prior to the contract month."
Have a look at the expiration calendar
https://www.cmegroup.com/tools-informat ... -calendar/
"Trading terminates 3 business day prior to the 25th calendar day of the month prior to the contract month. If the 25th calendar day is not a business day, trading terminates 4 business days prior to the 25th calendar day of the month prior to the contract month."
Have a look at the expiration calendar
https://www.cmegroup.com/tools-informat ... -calendar/
Re: How to identify place where linked contracts in continuous contract?
Thank you. It is correct information! Do you know how to calculate this dates in Multicharts?from CME website link provided earlier and it states following
"Trading terminates 3 business day prior to the 25th calendar day of the month prior to the contract month. If the 25th calendar day is not a business day, trading terminates 4 business days prior to the 25th calendar day of the month prior to the contract month."
Have a look at the expiration calendar
https://www.cmegroup.com/tools-informat ... -calendar/
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: How to identify place where linked contracts in continuous contract?
Yes, the rollover date is important information to know if you are trading crude oil futures. Unfortunately that date is determined differently by each data vendor. Sometimes a fixed date and sometimes when more volume arrives in the next contract, or in the case of Interactive Brokers possibly just made up from random information. All is not lost however; as you can calculate the day you want to roll by using a day offset from the native PowerLanguage keyword named ExpirationDate. So your code might look like this:
You can download the continuous contract from BarChart.com and that has the individual contracts listed if that helps you visualize the dates, but that might not be the same as IQFeed.
Code: Select all
vars: DTE(DateToJulian(ExpirationDate)), DaysB4Exp(5), MP(0);
if getappinfo(aiStrategyAuto)=1 then MP=MarketPosition_at_Broker else MP=MarketPosition;
// Get out if expiring soon
if DateToJulian(Date)>=DTE-DaysB4Exp then
begin
if GetAppInfo(aiRealTimeCalc)=1 then Alert("Expiring contract - Roll!");
if MP>0 then Sell next bar market
else if MP<0 then BuyToCover next bar market;
end;
Re: How to identify place where linked contracts in continuous contract?
Hello, thank you for answer. But on continuous contracts ExpirationDate is not working. I need it for backtest. Expiration date is 25 date of every month minus 3 days, if 25 is holiday then -4 days. How to calculate this in MC, I don't knowYes, the rollover date is important information to know if you are trading crude oil futures. Unfortunately that date is determined differently by each data vendor. Sometimes a fixed date and sometimes when more volume arrives in the next contract, or in the case of Interactive Brokers possibly just made up from random information. All is not lost however; as you can calculate the day you want to roll by using a day offset from the native PowerLanguage keyword named ExpirationDate. So your code might look like this:You can download the continuous contract from BarChart.com and that has the individual contracts listed if that helps you visualize the dates, but that might not be the same as IQFeed.Code: Select all
vars: DTE(DateToJulian(ExpirationDate)), DaysB4Exp(5), MP(0); if getappinfo(aiStrategyAuto)=1 then MP=MarketPosition_at_Broker else MP=MarketPosition; // Get out if expiring soon if DateToJulian(Date)>=DTE-DaysB4Exp then begin if GetAppInfo(aiRealTimeCalc)=1 then Alert("Expiring contract - Roll!"); if MP>0 then Sell next bar market else if MP<0 then BuyToCover next bar market; end;
qm.txt
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: How to identify place where linked contracts in continuous contract?
Hi Xurma,
Please be aware that the CME settlement date is not the same as the rollover date that your data provider uses for continuous contracts. If you cannot backtest on each individual contract month in Portfolio Trader and must use a continuous contract, then you will have to construct your own or find out what method they use to roll.
If you just want to re-create the formula for crude oil settlement, then the basic code would look like this: This code only checks for weekends; the full solution requires checking for holidays also and is non-trivial so you would probably have to pay a programmer to provide that. But first make sure what you need.
Please be aware that the CME settlement date is not the same as the rollover date that your data provider uses for continuous contracts. If you cannot backtest on each individual contract month in Portfolio Trader and must use a continuous contract, then you will have to construct your own or find out what method they use to roll.
If you just want to re-create the formula for crude oil settlement, then the basic code would look like this:
Code: Select all
vars: WD(0), MD(0);
// Current day. 0-Sunday, 6-Saturday
WD=DayOfWeek(D);
// Current date. days are 1-31
MD=DayOfMonth(D);
// Roll 20th-22nd depending on weekends
if MD=20 and (WD=3 or WD=4 or WD=5) then print("Rolling on 3 days prior: ", DateToString(DateTime))
// In 4 days the 25th falls on a weekend
else if MD=21 and (WD=2 or WD=3) then print("Rolling on 4 days prior: ", DateToString(DateTime))
// 25th in 3 days and not on Saturday or Sunday
else if MD=22 and (WD=1 or WD=2) then print("Rolling on 3 days prior: ", DateToString(DateTime));
Re: How to identify place where linked contracts in continuous contract? [SOLVED]
Thank you, really good solution!Hi Xurma,
Please be aware that the CME settlement date is not the same as the rollover date that your data provider uses for continuous contracts. If you cannot backtest on each individual contract month in Portfolio Trader and must use a continuous contract, then you will have to construct your own or find out what method they use to roll.
If you just want to re-create the formula for crude oil settlement, then the basic code would look like this:This code only checks for weekends; the full solution requires checking for holidays also and is non-trivial so you would probably have to pay a programmer to provide that. But first make sure what you need.Code: Select all
vars: WD(0), MD(0); // Current day. 0-Sunday, 6-Saturday WD=DayOfWeek(D); // Current date. days are 1-31 MD=DayOfMonth(D); // Roll 20th-22nd depending on weekends if MD=20 and (WD=3 or WD=4 or WD=5) then print("Rolling on 3 days prior: ", DateToString(DateTime)) // In 4 days the 25th falls on a weekend else if MD=21 and (WD=2 or WD=3) then print("Rolling on 4 days prior: ", DateToString(DateTime)) // 25th in 3 days and not on Saturday or Sunday else if MD=22 and (WD=1 or WD=2) then print("Rolling on 3 days prior: ", DateToString(DateTime));