help with expiration dates for options. - futures io
futures io futures trading

help with expiration dates for options.

Discussion in TradeStation

    1. trending_up 343 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments

Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

Search this Thread

help with expiration dates for options.

(login for full post details)
  #1 (permalink)
quintana roo, méxico
Posts: 79 since Mar 2013
Thanks: 222 given, 38 received

regards to everyone.

i have been working on an open source trading platform to create an automated options trading system to place trades based on alerts generated by ts. i have been able to get ts to appropriately calculate some necessary values like the strike prices to be selected but i have had significant problems with the expiration dates that should be printed as text for my automated system to trade.

expiration dates have been hard to get right because of ts's date formats, because there are many different cases and also because there are some exceptions.

if anyone can help me with this code i'm working on or point me to working examples i will be most grateful.

- the first thing to get right would be the exceptions. expiration dates for weekly options are always fridays, but once or twice a year when a market holiday falls on a friday the expiration date is moved to the preceding thursday.

it would be too difficult for me to create two parallel structures, one for thursdays and one for fridays, particularly when there are very few cases when options expiration is moved to a thursday. what i think could work would be to create two inputs for the expiration dates. if the next expiration date was a thursday i would just input that date by hand on input number 1 and ts should use it. if the expiration falls on a friday as usual, i would leave the first input blank, and ts should use the second input which would take 3 values.

so, ¿is this kind of structure possible in ts? ¿can i have a string input that i would just leave blank and in that case ts should ignore it but if it is not blank then it should use that value?

typical expiration on friday.
string thuexp(""),
string poscas(a or b or c);

expiration on a thursday.
string thuexp("190418"),
string poscas(a or b or c);

- the second aspect i have been having a hard time with is choosing the appropriate expiration date. i would normally want all contracts to be bought for the same week as this keeps risk to a minimum, however, i have realized there could be 3 different cases. a) monday to friday, return the date for the friday of this same week. b) monday to thursday, return the date for the friday of this same week, if it is a friday, return the date of the friday of the next week. c) return the date of the friday of the next week

¿would there be any way to combine the inputs i described above with the script below in ts?

if thuexp is not blank, return or print thuexp.

if thuexp is blank, use the value for poscas to determine the appropriate expiration date.

for case a,

return date for friday of this week in yymmdd format.

for case b,

if dow <= 4,

return date for friday of this week in yymmdd format..

if dow = 5,

return date for the friday of the next week in yymmdd format.

for case c,

return date for the friday of the next week in yymmdd format.

the people with ts support provided some this very sample code below but i haven't been able to get it to work as desired, and i have no idea where i should insert all the conditional cases described above. i have been working on the script below but it would only cover case b.

using elsystem;


// returns a string in the format yymmdd from a datetime object
method string getnextexpdat(datetime dt)
int dow,
datetime nextexpdat;

nextexpdat = dt;

dow = dayofweek( nextexpdat.eldate );

if dow = 5 then
nextexpdat.adddays( 7 * edwa )
nextexpdat.adddays( 5 - dow );

return nextexpdat.format( "%y%m%d" );


print( getnextexpdat(bardatetime) );

very well, thanks to all, regards.

Reply With Quote

futures io Trading Community Platforms and Indicators TradeStation > help with expiration dates for options.

Last Updated on June 9, 2019

Upcoming Webinars and Events

NinjaTrader Indicator Challenge!


Battlestations! Show us your trading desk - $1,500 in prizes!


Importance of Finding Your Own Way w/Adam Grimes

Elite only

Journal Challenge w/Jigsaw


Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
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.
no new posts