GetATMOption Command Error

Gupta

New member
Hi it is currently saturday as I am writing this, and my problem is that the second line of code returns the ATM option contract but the third line of code does not, even though it is the same date. I am running this on symbol APA.
Code:
def expdate = getYYYYMMDD();

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), 20230114));

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), (expdate+8)));

The error I get on the chart when trying to run this is:

Study1: Invalid value for days: 33
I assume I need to convert expdate+8 into a different format as it might be registering as another datatype? I am not sure. Could also due to it being a weekend but it works when I manually type in the date.

UPDATE:
Okay so the code does work but you have to refresh the chart. It still gives the error about invalid days not sure why but it kind of works now.
 
Last edited by a moderator:
Solution
Hi it is currently saturday as I am writing this, and my problem is that the second line of code returns the ATM option contract but the third line of code does not, even though it is the same date. I am running this on symbol APA.
Code:
def expdate = getYYYYMMDD();

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), 20230114));

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), (expdate+8)));

The error I get on the chart when trying to run this is:

Study1: Invalid value for days: 33
I assume I need to convert expdate+8 into a different format as it might be registering as another datatype? I am not sure. Could also due to it being a weekend but it works when I manually type in the date.

UPDATE:
Okay so the code does...
Hi it is currently saturday as I am writing this, and my problem is that the second line of code returns the ATM option contract but the third line of code does not, even though it is the same date. I am running this on symbol APA.
Code:
def expdate = getYYYYMMDD();

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), 20230114));

AddLabel(yes, GetATMOption(GetUnderlyingSymbol(), (expdate+8)));

The error I get on the chart when trying to run this is:

Study1: Invalid value for days: 33
I assume I need to convert expdate+8 into a different format as it might be registering as another datatype? I am not sure. Could also due to it being a weekend but it works when I manually type in the date.

UPDATE:
Okay so the code does work but you have to refresh the chart. It still gives the error about invalid days not sure why but it kind of works now.

take a look at the posts in this thread, i think they will help reading options data
https://usethinkscript.com/threads/options-capture-option-chain-data-via-thinkscript.3871/
 
Solution

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

Scripts are evaluated against every individual bar on the chart, from left to right, as the script loads. The YYYYMMDD date which is submitted to GetATMOption() can not have a DD higher than 31. You're adding 8 days to the date, so as the script loads, any day-of-month throughout the entire chart which is above the 23rd will cause an error along the way.

You would have to ensure that the proper bar is being evaluated, like:

def expdate = if !isNaN(close) and isNaN(close[-1]) then getYYYYMMDD() else 19020101;

The date in general can't be lower than Jan 1st 1902.

Dates with a month above 12, or a day above 31, and things like that, are completely invalid, and will cause an error.

Dates which are valid, but do not necessarily have options expire on them, like 19020101, will just return a "blank" option code.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
378 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.
Back
Top