Passing a date variable into options functions

miler4salem

New member
I'm trying to work on some thinkscript open interest and volume plots and am stumped by the fact that I can't seem to pass a date into a function like GetATMOption after creating a variable for today's date. I have tried compiling the date from the day of month, month, and year functions and have tried adding days to the GetYYYYMMDD function but I keep getting N/A in my chart.

The script works fine if I just type in the date or create a variable with the date in it. However, I'd like to dynamically have the date update.
 
Solution
I'm trying to work on some thinkscript open interest and volume plots and am stumped by the fact that I can't seem to pass a date into a function like GetATMOption after creating a variable for today's date. I have tried compiling the date from the day of month, month, and year functions and have tried adding days to the GetYYYYMMDD function but I keep getting N/A in my chart.

The script works fine if I just type in the date or create a variable with the date in it. However, I'd like to dynamically have the date update.

what did you try?
what day of the week are you trying to calculate a date for?

for monthly options, the date should be the 3rd saturday of the month.
i copied the examples from the GetATMOption page and...
I'm trying to work on some thinkscript open interest and volume plots and am stumped by the fact that I can't seem to pass a date into a function like GetATMOption after creating a variable for today's date. I have tried compiling the date from the day of month, month, and year functions and have tried adding days to the GetYYYYMMDD function but I keep getting N/A in my chart.

The script works fine if I just type in the date or create a variable with the date in it. However, I'd like to dynamically have the date update.

what did you try?
what day of the week are you trying to calculate a date for?

for monthly options, the date should be the 3rd saturday of the month.
i copied the examples from the GetATMOption page and changed them slightly, so they plot the put price on a lower chart.
this makes 2 plots. 1 is based on an entered expire date.
the other plot is based on a calculated expire date, for the next saturday. this one only plots data during the current day.

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/GetATMOption

INTC 5 min chart 1/22 put and 2/19 put
RrW3cqB.jpg


Ruby:
# option_getatm_00

def today = GetYYYYMMDD();
# get current day of week number
# this is a number.  mon=1, tues=2,.. fri=5, sun=7
def dow = (GetDayofWeek(today));
addlabel(1, "day of week # " + dow, color.magenta);

# this assumes it is the 3rd week of month, doesn't adjust date if it isn't
# calc diff to sat ( 3rd sat of month is common expire date)
def desired_day = 6;
def diff1 =  desired_day - dow;
def ddate1 = today + diff1;

addlabel(1, "diff1 " + diff1, color.magenta);
addlabel(1, "ddate1 " + ddate1, color.magenta);

AddLabel(IsOptionable(), ddate1 + " ATM put option is " + GetATMOption(GetUnderlyingSymbol(), ddate1, OptionClass.put), color.magenta);

plot ATM1 = close(GetATMOption(GetUnderlyingSymbol(), ddate1, OptionClass.PUT));
ATM1.setdefaultcolor(color.magenta);


addlabel(1, "----", color.gray);

# --------------------------------------------

# https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/GetATMOption
# Example 1
#input expire_date1 = 20220122;
input expire_date2 = 20220219;

#def dat1_mmdd =  10000 * ( expire_date1 - (expire_date1/10000));
def dat2a =  (expire_date2/10000);
def dat2b =  dat2a - floor(dat2a);
def dat2_mmdd = dat2b * 10000;
addlabel(1, "mmdd " + dat2_mmdd, color.cyan);

#AddLabel(IsOptionable(), expire_date1 + " ATM put option is " + GetATMOption(GetUnderlyingSymbol(), expire_date1, OptionClass.put), color.yellow);
AddLabel(IsOptionable(), expire_date2 + " ATM put option is " + GetATMOption(GetUnderlyingSymbol(), expire_date2, OptionClass.put), color.cyan);

#This script adds a chart label showing the code of the at-the-money Call option of currently chosen symbol with expiration date April 21, 2012.

#Example 2
declare lower;
#plot ATMPut1 = close(GetATMOption(GetUnderlyingSymbol(), expire_date1, OptionClass.PUT));
#ATMPut1.setdefaultcolor(color.yellow);
plot ATMPut2 = close(GetATMOption(GetUnderlyingSymbol(), expire_date2, OptionClass.PUT));
ATMPut2.setdefaultcolor(color.cyan);

#This script plots the Close price of the at-the-money Put option of currently chosen symbol with expiration date April 21, 2012.
#
 
Solution

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

Hello
In this post you mentioned you are trying to draw openinterest levels/lines on an intraday chart, what I am thinking is top 5 openinterests for the options expiring coming friday (so just weeklys) , so higher the openinterest thicker the line, and same for puts , so on one chart 10 lines , 5 top calls/oi and 5 top put/oi and system should automatically take expiry as friday. is it possible or if you know if it already exist. Plotting the strikes. Thanks.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
637 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