Futures Expiry Syntax

Questions about MultiCharts and user contributed studies.
brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

I have a strategy that buy/sell depends on number of (trading days) to expiry for a futures contract.

Is it possible to reference such field in multicharts code?

Thanks.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Futures Expiry Syntax

Postby TJ » 01 Apr 2014

I have a strategy that buy/sell depends on number of (trading days) to expiry for a futures contract.
Is it possible to reference such field in multicharts code?
Thanks.
Yes, you can use the keyword: ExpirationDate


For a list of available keywords,
look under PowerLanguage Keyword Reference
https://www.multicharts.com/trading-sof ... /Main_Page

brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Re: Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

I have a strategy that buy/sell depends on number of (trading days) to expiry for a futures contract.
Is it possible to reference such field in multicharts code?
Thanks.
Yes, you can use the keyword: ExpirationDate


For a list of available keywords,
look under PowerLanguage Keyword Reference
https://www.multicharts.com/trading-sof ... /Main_Page

TJ, Thanks for reading and replying my posts all the time.

I tried to use it but get a constant number which didnt make sense "239,700.00"

This is my code, what do you think the problem is?

"Plot1( ExpirationDate - Date, "NoOfDaysToExp" ) ;"

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Futures Expiry Syntax

Postby TJ » 01 Apr 2014

I have a strategy that buy/sell depends on number of (trading days) to expiry for a futures contract.
Is it possible to reference such field in multicharts code?
Thanks.
Yes, you can use the keyword: ExpirationDate
For a list of available keywords,
look under PowerLanguage Keyword Reference
https://www.multicharts.com/trading-sof ... /Main_Page
TJ, Thanks for reading and replying my posts all the time.
I tried to use it but get a constant number which didnt make sense "239,700.00"
This is my code, what do you think the problem is?
"Plot1( ExpirationDate - Date, "NoOfDaysToExp" ) ;"
Have you looked under PowerLanguage Keyword Reference?
All the keyword definitions are there, including usage examples.


ps. it would help if you provide more information on your test. e.g the name of the instrument, so that other people can test and verify it on their side too.

ps. look up also the keyword definition of "Date".

brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Re: Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

Code: Select all

Variables:
dateToday(0), dateTodayFormat(0),dateFutExp(0), dateFutExpFormat(0);

// 1. Assign the date of today to the variable 'dateToday'
dateToday = Date;
//Print("The current date in YYYMMdd format is: ", dateToday, NewLine);

// 2. Now, convert the date to DateTime format
dateTodayFormat = ELDateToDateTime(dateToday);
//Print("The current date in DateTime format is: ", NumToStr(dateTodayFormat , 5), NewLine);

// 1. Assign the date of today to the variable 'dateToday'
dateFutExp = ExpirationDate;
//Print("The current date in YYYMMdd format is: ", dateToday, NewLine);

// 2. Now, convert the date to DateTime format
dateFutExpFormat = ELDateToDateTime(dateFutExp);
//Print("The current date in DateTime format is: ", NumToStr(dateFutExpFormat , 5), NewLine);

Print("Number of days to expiry is ", NumToStr(dateFutExpFormat - dateTodayFormat, 5), NewLine);

Plot1( dateFutExpFormat - dateTodayFormat, "NoOfDaysToExp" ) ;
I have coded the above on symbol "@VXJ14" and "@VX#".

It is strange that the ExpirationDate is returning as Today. i.e. 2nd April. The expiry should be 16th April.

It seems the ExpirationDate field is not expressing what it should be?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Futures Expiry Syntax

Postby TJ » 01 Apr 2014

Who is your data provider?
What is the expiry date in the QuoteManager?

Give this a try:

Code: Select all


If lastbaronchart then
begin

once begin
print("Today's date = ", date+19000000:0:0, newline,
" Expiry date for "+symbolname+" = "+ text(expirationdate+19000000:0:0));
end;

end;

ps. you should post your print out, so that people can help trace the errors for you.

brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Re: Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

I have attached the screen shot here.

The problem is it seems the expiry date extracted are not the actual expiry dates.

All the contracts expires around the 1st of the month, which explains why I get a value of 0 for the April14 contract (as it expires today).

The real expiry date should be mid April, and should be mid month for every month.

So is the ExpirationDate field reliable?
Attachments
MC_Capture.PNG
(69.32 KiB) Downloaded 812 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Futures Expiry Syntax

Postby TJ » 01 Apr 2014

I have attached the screen shot here.
The problem is it seems the expiry date extracted are not the actual expiry dates.
All the contracts expires around the 1st of the month, which explains why I get a value of 0 for the April14 contract (as it expires today).
The real expiry date should be mid April, and should be mid month for every month.

So is the ExpirationDate field reliable?
MultiCharts gets the ExpirationDate from your data provider.

Go to QuoteManager, double click on symbol,
you can see the expiry date of the contract.

Image
Attachments
Expiry Date.jpg
(31.94 KiB) Downloaded 848 times

brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Re: Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

Thanks TJ, I am using IQFeed at the moment. Checking if they dont provide "good" futures exp dates.

brianhclo
Posts: 31
Joined: 31 Mar 2014
Has thanked: 8 times

Re: Futures Expiry Syntax

Postby brianhclo » 01 Apr 2014

IQFeed came back and its a mistake on their end.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Futures Expiry Syntax

Postby TJ » 01 Apr 2014

IQFeed came back and its a mistake on their end.
Good that you found out now... instead of later.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Futures Expiry Syntax

Postby Henry MultiСharts » 02 Apr 2014

The expiration date in QuoteManager is calculated based on the expiration rule for the instrument's symbol root. You can find the symbol root for a particular instrument in QuoteManager->Edit symbol->Futures tab.
You can find the symbol dictionary in QuoteManager->Tools->Symbol Dictionary.
In the symbol dictionary please select IQFeed->@VX->Edit->set Expiration rule to "Third Tuesday".
The expiration date will be automatically recalculated for all of the instruments from this data provider using this rule.


Return to “MultiCharts”