• Get $40 off VIP by signing up for a free account! Sign Up

GetDaysToExpiration in Options Chain


New member
Ultimately, I'm trying to add a column that calculates the annualized return on risk capital of selling a put, assuming it expires worthless.
So the formula for that would be something like this:

def premium = 100*(ask+bid)/2;
def commission = 0.65;
def riskCapital = 100*GetStrike() - premium;
def dte = GetDaysToExpiration();
plot ARORC = 100*((premium-commission) /riskCapital) * (365/dte);

But when I add this custom column to Options Chain, it often reports the wrong ARORC compared to my hand calculated values using the same formula.

So I break down the individual components as separate custom columns, and I find that GetDaysToExpiration() returns a number but that number is not really the days to expiration of that option. For example, on May 14th, the option BABA200515P85, GetDaysToExpiration is returning "15", when it should be returning "1".

Am I doing something wrong, or can anyone think of another way to accomplish the same end result?
I coincidentally just ran into this same problem with GetDaysToExpiration() not returning the correct DTE. Any insight on working around this would be most helpful. I discovered that the following functions are also displaying inconsistent values for a given option chain: Getday() and getyyyymmdd ()

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I see the same issue with the Option Hacker scan. For example ABT with a 31 JUN 20 expiration has DTE's of 15,19, 27,16, 18 and 22 days for the various strike prices. After looking at the data, it appears that the Monthly expiration DTE's are correct, but the Weeklies and Adjusted ones appear random. I'm new to the platform and not sure how support works or if it exists for the scripting software. I emailed tech support a few days ago, but haven't heard back. Is that the right approach to report a suspected bug, I mean undocumented feature?
I'm using the Days study in a column to display the remaining life of an option contract.

First issue: I'd like to limit it to display only on options. That is, stocks, ETFs, funds, etc. should be blank. I don't know how code the trap when something other than a digit is received.

For example, this doesn't work:

if isNaN(getdaystoexpiration()-1) then "display nothing" else getdaystoexpiration()-1;

Second question: This column has begun displaying the dreaded "custom expression subscription limit exceeded" message. It pretty much worked until today. I don't know what's changed.
I am running into the exact same issue and, after hours of searching the internet, I cannot find a solution!

As you said, the culprit of the problem is that the GetDaysToExpiration() function returns an incorrect number of days. In fact, various strikes within the SAME expiration date return a DIFFERENT number of days to expiration.

Is this really a bug that hasn't been fixed for years?!

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
213 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.