Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Has anyone had any issues with the GetATMOption method? I am writing a Max Pain script, and for the most part, it is working pretty well, but there are some random Expiration Dates that the GetATMOption method just will not detect, but they exist in the Options Chain.
This code is pretty simple, yet it does not work. Does anyone else have trouble with this snippet of code? It works if I set the expiration to 20230531, but not 20230530, however, according to the Options Chain in TOS, there is an entire series of Options with an expiration date of 20230530. This is really the only issue I have left to work out with the script I have written. Once I get it ironed out I will post it, in the event anyone else wants it.
input expirationDate = 20230530;
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
# options_atm4_daily
#https://usethinkscript.com/threads/thinkscript-not-detecting-option.15630/
#Thinkscript not detecting Option
#input Date1 = 20230530;
#AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date1, OptionClass.PUT), color.yellow);
#input Date2 = 20230531;
#AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date2, OptionClass.PUT), color.yellow);
#input Date3 = 20230601;
#AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date3, OptionClass.PUT), color.yellow);
#input Date4 = 20230602;
#AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date4, OptionClass.PUT), color.yellow);
input Date6 = 20230605;
addlabel(1, " ", color.black);
addlabel(1, "date6 " + asprice(date6), color.magenta);
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date6, OptionClass.PUT), Color.YELLOW);
input Date7 = 20230606;
addlabel(1, " ", color.black);
addlabel(1, "date7 " + asprice(date7), color.magenta);
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date7, OptionClass.PUT), Color.YELLOW);
input Date8 = 20230607;
addlabel(1, " ", color.black);
addlabel(1, "date8 " + asprice(date8), color.magenta);
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date8, OptionClass.PUT), Color.YELLOW);
input Date9 = 20230608;
addlabel(1, " ", color.black);
addlabel(1, "date9 " + asprice(date9), color.magenta);
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date9, OptionClass.PUT), Color.YELLOW);
input Date10 = 20230609;
addlabel(1, " ", color.black);
addlabel(1, "date10 " + asprice(date10), color.magenta);
AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date10, OptionClass.PUT), Color.YELLOW);
#
Thanks for the feedback! I def see that it would have been better to post the entire script, but it’s roughly 800 lines of code. I’ll post it in the morning. I did eventually work out the date issue you mentioned, and the way I got around it was by using the ‘GetNextExpirationOption’ method. I used that throughout my script, that way the correct date could be entered. Seeing that manually entering the date as a day prior seems to work based on your code, but without the use of the GetNextExpirationOption method, it may be something with that method that is causing the issue for me. Again, I’ll post it in the morning in its entirety, and if you have some more insight after reviewing it, that would be great.i'm going to repeat myself again,
please post complete codes.
doing so, really does help others help you debug. and it may have helped you see what is happening.
don't be bashful. everyone started out not knowing anything.
you say it is simple, but yet it doesn't work for you.... so it isn't simple.
tip1 , test codes on a normal week. don't test codes on a holiday week. the holiday may mess up/confuse you.
tip2 , if something doesn't work, add more labels / bubbles to display some values and see what is going on.
answer, specify a date that is the day after the desired option date.
Code:# options_atm4_daily #https://usethinkscript.com/threads/thinkscript-not-detecting-option.15630/ #Thinkscript not detecting Option #input Date1 = 20230530; #AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date1, OptionClass.PUT), color.yellow); #input Date2 = 20230531; #AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date2, OptionClass.PUT), color.yellow); #input Date3 = 20230601; #AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date3, OptionClass.PUT), color.yellow); #input Date4 = 20230602; #AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date4, OptionClass.PUT), color.yellow); input Date6 = 20230605; addlabel(1, " ", color.black); addlabel(1, "date6 " + asprice(date6), color.magenta); AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date6, OptionClass.PUT), Color.YELLOW); input Date7 = 20230606; addlabel(1, " ", color.black); addlabel(1, "date7 " + asprice(date7), color.magenta); AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date7, OptionClass.PUT), Color.YELLOW); input Date8 = 20230607; addlabel(1, " ", color.black); addlabel(1, "date8 " + asprice(date8), color.magenta); AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date8, OptionClass.PUT), Color.YELLOW); input Date9 = 20230608; addlabel(1, " ", color.black); addlabel(1, "date9 " + asprice(date9), color.magenta); AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date9, OptionClass.PUT), Color.YELLOW); input Date10 = 20230609; addlabel(1, " ", color.black); addlabel(1, "date10 " + asprice(date10), color.magenta); AddLabel(IsOptionable(), GetATMOption(GetUnderlyingSymbol(), Date10, OptionClass.PUT), Color.YELLOW); #
purple date is the data on input code line
yellow is the option symbol. notice the 1 day difference.
![]()
o , well if it's that long, you don't need to post it. using the next expiration day isn't the same as specifying the day after, so it won't always work.Th
Thanks for the feedback! I def see that it would have been better to post the entire script, but it’s roughly 800 lines of code. I’ll post it in the morning. I did eventually work out the date issue you mentioned, and the way I got around it was by using the ‘GetNextExpirationOption’ method. I used that throughout my script, that way the correct date could be entered. Seeing that manually entering the date as a day prior seems to work based on your code, but without the use of the GetNextExpirationOption method, it may be something with that method that is causing the issue for me. Again, I’ll post it in the morning in its entirety, and if you have some more insight after reviewing it, that would be great.
Thanks!
Got it. Makes sense after I think about it in more detail. I will just change the code back to the original, and I will enter the day prior to expiration. Thanks!o , well if it's that long, you don't need to post it. using the next expiration day isn't the same as specifying the day after, so it won't always work.
can someone refer how to calculate option max pain code ?
did you create thinkscript ?
i tried the code its showign as N/A for SPY, spx, AAPL for 20240503 input date - Appreciate the response - Raj
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | Max Price Change For Past x Bars | Questions | 2 | |
![]() |
Max Drawdown Watchlist Column | Questions | 1 | |
![]() |
How to create an unbounded Max input in a normalizePlot() script? | Questions | 7 | |
B | Previous body max/min is in the top/bottom 5% of the current body | Questions | 3 | |
G | Limit plot to Max of One Candle | Questions | 5 |
Start a new thread and receive assistance from our community.
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.
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.