# 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.
#