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 ()


New member
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?


New member
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.

Similar threads