Options: Capture Option Chain Data via Thinkscript

DoQtorNo

Member
Howdy and good am,

I am using the Option Hacker to pull my option candidates. I get the Symbol and Description Return. Is there a way I can capture the following:

a. option bid, ask for the particular option it pulls

b. implied volatility for the particular option chain and the anticipated +- dollar movement (the numbers to the left above the header of the particular option chain
c. option date
d. call or put

Here's the data the scan hack is returning:

.AZN201016C57.5
 

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

So i guess there is no way to build a strategy that has an entry on a close crossing an ema on a tick chart and having the close be when first out of the money option (that is on the same side) having its bid or last being 10% from what its ask was at time of entry
correct
 
I like this script. Is there a way to change the font text color to white on the OTM call labels? Any ideas how this can be used as a scan?
@ksadras Here is the code I am currently using... Feel free to modify it to your needs just as I did...

Ruby:
# Weekly Options Implied Volatility Plotted intraday
# Mobius
# Chat Room Request
# 02.27.2016
#
# 2021-07-01 : Modified by rad14733 for personal needs

declare Once_Per_Bar;

input series = 1;
input showBands = no;
input show_itm_labels = yes;
input show_atm_labels = yes;
input show_otm_labels = yes;
input Days_In_Contract = 0;
Assert(series > 0, "'series' must be positive: " + series);

def RTHopen = open(period = AggregationPeriod.Day);
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1); # First DOM is this DOW
def FirstFridayDOM1 = if Day1DOW1 < 6
    then 6 - Day1DOW1
    else if Day1DOW1 == 6
         then 7
         else 6;

def SecondFridayDOM = FirstFridayDOM1 + 7;
def ThirdFridayDOM = FirstFridayDOM1 + 14;
def FourthFridayDOM = FirstFridayDOM1 + 21;
def RollDOM = FirstFridayDOM1 + 21; #14; changed to 21 to pick up all Fridays of the current month for weekly options
def ExpMonth1 = if RollDOM > CurrentDOM
    then CurrentMonth + series - 1
    else CurrentMonth + series;
def ExpMonth2 = if ExpMonth1 > 12
    then ExpMonth1 - 12
    else ExpMonth1;

def ExpYear = if ExpMonth1 > 12
    then CurrentYear + 1
    else CurrentYear;

def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
def FirstFridayDOM = if Day1DOW < 6
    then 6 - Day1DOW
    else if Day1DOW == 6
         then 7
         else 6;

def ExpDOM = if currentDOM < FirstFridayDOM -1
    then FirstFridayDOM1
    else if between(currentDOM, FirstFridayDOM, SecondFridayDOM-1)
         then SecondFridayDOM
         else if between(currentDOM, SecondFridayDOM, ThirdFridayDOM-1)
              then ThirdFridayDOM
              else if between(currentDOM, ThirdFridayDOM, FourthFridayDOM-1)
                   then FourthFridayDOM
                   else FirstFridayDOM;

def NextFriday = DaysTillDate(ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM);
def ExpirationDate = GetYYYYMMDD() + NextFriday;
def ExpData = (ExpirationDate / 1) + 1;
def yr = Round(GetYear() / 100, 0);
def yr2 = GetYear() - 2000;
def OptionDateString = ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM + 1;
def ATMCprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))
    then ATMCprice[1]
    else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL));

def ATMPprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)))
    then ATMCprice[1]
    else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT));

def HPD = if Days_In_Contract == 0 #HPD = Holding Period Days
    then NextFriday
    else Days_In_Contract;

def t = HPD / 365;

def ClosedForm_IV_est = if isNaN(((ATMCprice[1] * Sqrt(2 * Double.Pi)) / (RTHopen * Sqrt(t)))) then ClosedForm_IV_est[1]    else ((ATMCprice * Sqrt(2 * Double.Pi)) / (RTHopen * Sqrt(t)));

def Intraday_IV = if ClosedForm_IV_est > 0 then ClosedForm_IV_est else double.nan;
def ImpMove = Round((close[1] * Intraday_IV / Sqrt(365)) / tickSize(), 0) * tickSize();

plot upper = RTHopen + ImpMove[1];
upper.SetStyle(Curve.Firm);
upper.SetDefaultColor(Color.Cyan);
upper.SetHiding(!showBands);

plot lower = RTHopen - ImpMove[1];
lower.SetStyle(Curve.Firm);
lower.SetDefaultColor(Color.Cyan);
lower.SetHiding(!showBands);

def ActualMove = close[1] - RTHopen;


# Next OTM Prices

def OTMCprice = if isNaN(close(symbol = GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))) then OTMCprice[1] else close(symbol = GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)));

def OTMPprice = if isNaN(close(symbol = GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)))) then ATMCprice[1] else close(symbol = GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)));


# Next ITM Prices

def ITMCprice = if isNaN(close(symbol = GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))) then ITMCprice[1] else close(symbol = GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)));

def ITMPprice = if isNaN(close(symbol = GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)))) then ITMPprice[1] else close(symbol = GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)));


# AddLabels

AddLabel(show_itm_labels and IsOptionable(), "ITM Call: " + GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)) + " = " + AsDollars(ITMCprice), Color.GREEN);

AddLabel(show_itm_labels and IsOptionable(), "ITM Put: " + GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)) + " = " + AsDollars(ITMPprice), Color.GREEN);

AddLabel(show_atm_labels and IsOptionable(), "ATM Call: " + GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL) + " = $" + ATMCprice, Color.LIGHT_GRAY);

AddLabel(show_atm_labels and IsOptionable(), "ATM Put: " + GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT) + " = $" + ATMPprice, Color.LIGHT_GRAY);

AddLabel(show_otm_labels and IsOptionable(), "OTM Call: " + GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)) + " = " + AsDollars(OTMCprice), Color.RED);

AddLabel(show_otm_labels and IsOptionable(), "OTM Put: " + GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)) + " = " + AsDollars(OTMPprice), Color.RED);


# End Code Weekly Options
ript
 
I like this script. Is there a way to change the font text color to white on the OTM call labels? Any ideas how this can be used as a scan?

ript
ToS does not allow the font text color to be changed.
The ToS Options Hacker Module doesn't allow the using of custom scripts to scan against options related data. We aren't allowed to use custom Thinkscript code in the Options Scanner. :(
 
How to see increasing premium for a stock for option trade
Hi All,
I am not good in writing code, so I need help in creating a script or setup in ThinkAndSwim to know increasing premium for a stock so that i can play option.

Thanks,
BT
 
Last edited by a moderator:
How to see increasing premium for a stock for option trade
Hi All,
I am not good in writing code, so I need help in creating a script or setup in ThinkAndSwim to know increasing premium for a stock so that i can play option.

Thanks,
BT
The ToS Options Hacker Module doesn't allow the using of custom scripts to scan against options related data. We aren't allowed to use custom Thinkscript code in the Options Scanner. :(
 
I'm trying to create a ThinkScript that will show Implied Volatility percent change from the day prior in the options chain. It doesn't have to be anything fancy, and doesn't even necessarily have to be in percent format. Please let me know if this is possible and how to do so.
were u able to find something like this? have been looking also
 
I would like to get in a chart bubble the atm call and put price at close prior to earning announcements, in order to see if there was a call or put bias in pricing. Can someone help me adapt Mobius's code above to do that?

Perhaps these lines from Modius's code above:
def ATMCprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString,
OptionClass.CALL)))
then ATMCprice[1]
else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL));)

can be inserted in the code below (found in another post):

def price = close;
def estimate = GetEstimatedEarnings();
def actual = GetActualEarnings();
def get_price = if estimate and actual then price else get_price[1];
def gain = (actual – estimate);

AddChartBubble(estimate, close, "Gap: " + (((open[-1] - close)/close)*100)+"% " + “Est: ” + estimate + “\nAct: ” + actual + (if gain <= 0 then "\nLoss: " else “\nGain: ”) + gain, if actual <= estimate then CreateColor(247, 25, 91) else CreateColor(25, 202, 247));

so that the bubble includes atm call and put prices.
 
Last edited:
This is sort of what you want, just needs a little work:

Code:
# Weekly Options Implied Volatility Plotted intraday
# Mobius
# Chat Room Request
# 02.27.2016

declare Once_Per_Bar;

input series = 1;
input show_label = yes;
input Days_In_Contract = 0;
Assert(series > 0, "'series' must be positive: " + series);

def RTHopen = open(period = AggregationPeriod.Day);
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1); # First DOM is this DOW
def FirstFridayDOM1 = if Day1DOW1 < 6
    then 6 - Day1DOW1
    else if Day1DOW1 == 6
         then 7
         else 6;

def SecondFridayDOM = FirstFridayDOM1 + 7;
def ThirdFridayDOM = FirstFridayDOM1 + 14;
def FourthFridayDOM = FirstFridayDOM1 + 21;
def RollDOM = FirstFridayDOM1 + 21; #14; changed to 21 to pick up all Fridays of the current month for weekly options
def ExpMonth1 = if RollDOM > CurrentDOM
    then CurrentMonth + series - 1
    else CurrentMonth + series;
def ExpMonth2 = if ExpMonth1 > 12
    then ExpMonth1 - 12
    else ExpMonth1;

def ExpYear = if ExpMonth1 > 12
    then CurrentYear + 1
    else CurrentYear;

def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
def FirstFridayDOM = if Day1DOW < 6
    then 6 - Day1DOW
    else if Day1DOW == 6
         then 7
         else 6;

def ExpDOM = if currentDOM < FirstFridayDOM -1
    then FirstFridayDOM1
    else if between(currentDOM, FirstFridayDOM, SecondFridayDOM-1)
         then SecondFridayDOM
         else if between(currentDOM, SecondFridayDOM, ThirdFridayDOM-1)
              then ThirdFridayDOM
              else if between(currentDOM, ThirdFridayDOM, FourthFridayDOM-1)
                   then FourthFridayDOM
                   else FirstFridayDOM;

def NextFriday = DaysTillDate(ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM);
def ExpirationDate = GetYYYYMMDD() + NextFriday;
def ExpData = (ExpirationDate / 1) + 1;
def yr = Round(GetYear() / 100, 0);
def yr2 = GetYear() - 2000;
def OptionDateString = ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM + 1;
def ATMCprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))

    then ATMCprice[1]

    else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL));

def HPD = if Days_In_Contract == 0 #HPD = Holding Period Days

    then NextFriday

    else Days_In_Contract;

def t = HPD / 365;

def ClosedForm_IV_est = if isNaN(((ATMCprice[1] * Sqrt(2 * Double.Pi)) / (RTHopen * Sqrt(t))))
                        then ClosedForm_IV_est[1]
                        else ((ATMCprice * Sqrt(2 * Double.Pi)) / (RTHopen * Sqrt(t)));

def Intraday_IV = if ClosedForm_IV_est > 0 then ClosedForm_IV_est else double.nan;
def ImpMove = Round((close[1] * Intraday_IV / Sqrt(365)) / tickSize(), 0) * tickSize();
plot upper = RTHopen + ImpMove[1];
plot lower = RTHopen - ImpMove[1];

upper.SetStyle(Curve.Firm);
upper.SetDefaultColor(Color.Cyan);
lower.SetStyle(Curve.Firm);
lower.SetDefaultColor(Color.Cyan);

def ActualMove = close[1] - RTHopen;

AddLabel(show_label and IsOptionable(), "ATM Call option is " +          GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL) +         " Price = $" +           ATMCprice +        "  Intraday IV = " +           AsPercent(ClosedForm_IV_est) +       "  Implied Move = +- " +          AsDollars(ImpMove) +       "  Actual Move = " +          AsDollars(ActualMove)
, if close > RTHopen then color.GREEN else color.RED);

# End Code Weekly Options
anyway to make one for puts? and the label in the script has option data ie: ATM call option and its price. I was wonder if it’s possible to also put the volume of that call on the label too
 
Last edited by a moderator:
anyway to make one for puts? and the label in the script has option data ie: ATM call option and its price. I was wonder if it’s possible to also put the volume of that call on the label too
I haven't work with this script or these functions but did you try changing all instances of OptionClass.CALL to OptionClass.PUT
The ToS data feeds do not include put and call volume.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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