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
 

BenTen

Administrative
Staff member
Staff
VIP
Do you mean adding things like IV to this section? If so, click on the tiny gear icon on the right-hand side and then add different columns to it.

mKqAWb9.png
 

DoQtorNo

Member
thank you. I get the search retuls but I wanted to know how I can capture the option chain information and put it on a label on a chart. I twould keep me from having to go back an forth between the scan results and teh chart. I'm looking at the nake underlying chart versus copying and pasting the option data. So the label would include the option data (i.e. option chain data, type of option (call or put), exp date strike price, etc).
 

Chuck

Well-known member
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
 

barbaros

Well-known member
VIP
I have an idea about an options indicator that depends on the ability to get the option code or the strike price of the option for the underlying symbol at a certain delta for a specified expiration date. Is this possible with ThinkScript?

So, pretty much,

Inputs:
  • Symbol
  • Current Price
  • Expiration Date
  • Delta
Output:
  • Strike Price or Option Code
 
Last edited:

barbaros

Well-known member
VIP
@rad14733 I’m essentially trying to add a label on a chart that shows the strike price of certain delta options with a specified expiration.

For example, SPY chart, add the script once and input exp time in 7 days with 30 delta and select put. Then, you can add the indicator many times to see different strike prices of exp time and deltas.

Then, if you can get the bid and ask prices of those strikes, you can calculate prices of spreads all in one chart.
 

rad14733

Well-known member
VIP
@barbaros That sounds more like something you would accomplish using a scan rather than a chart study...
I don't see an effective way of generating a list of Put options after every chart repaint.
 
Last edited by a moderator:

ksadras

New member
VIP
I am trying to get the call and put price of a ticker that is the next to near time expiring and display in the label the prices.
Example
SPY
Current Price 4334
I want to get the PUT and CALL price for 4335 expiring in 0 or 1 DTE
 

ksadras

New member
VIP
I am trying to get the call and put price of a ticker that is the next to near time expiring and display in the label the prices.
Example
SPY
Current Price 4334
I want to get the PUT and CALL price for 4335 expiring in 0 or 1 DTE
Here is the ask again. Some how I got no reply on this.

Example:
On any day, during market open I want to get the Call and Put price of the underlying symbol.
EXAMPLE: SPY the strike price is 4747

I want to get the

A) BID put price for 4050
SELL -1 SPX 100 (Weeklys) 11 AUG 21 4050 PUT @.50 LMT
and
B) BID call price for 4050
SELL -1 SPX 100 (Weeklys) 11 AUG 21 4050 CALL @1.50 LMT

And display in the label

SPY 4050 PUT: .50 4050 CALL: 1.50

The ask is: Can I query the option pricing of an underlying symbol to the nearest expiry for a given strike price?

Is this doable?
 

rad14733

Well-known member
VIP
@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
 

PickolastheMan

New member
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.
 

pontenkin

New member
Hi,

I would like to retrieve e.g. option price data and automatically update it with the next expiry date. However, I have failed it. I can easily retrieve the closing price of an option, for example:

def price= close(getatmoption(GetUnderlyingSymbol(), date, optionclass.call));

whereby "date" is pre-defined as any correct expiry date. If I try to retrieve the "next expiry" then I can easily accomplish it with, e.g.:

def price2 = close(getnextExpirationOption(getatmoption(GetUnderlyingSymbol(), date, optionclass.call)));

However, if I try to automate it indefinitely (from the begining to the end of the chart) then I fail misearably. I have tried to to do so with GetDaysToExpiration() as well as simply GetYYYYMMDD(), entering the value as the "date" variable before testing the query with "if isNaN(close(getatmoption(GetUnderlyingSymbol(), date, ......." It doesnt work either!

Do you have a suggestion as to how I could accomplish the following sketch?

def date = getYYYYMMDD;
def shift = 7; ## used to shift the variable "date" into the future

def price = if close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call)) exists
then close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call))
else if close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call)) doesn't exist
then find the closing price for the next expiry;
Plot xyz = price;

Unsure whether this is possible but I would appreciate any guidance/ help along this line. [FYI, I have looked extensively through the threads related to option handling and I cannot find anything similar to it.]

Many thanks!
 

halcyonguy

Active member
VIP
Hi,

I would like to retrieve e.g. option price data and automatically update it with the next expiry date. However, I have failed it. I can easily retrieve the closing price of an option, for example:

def price= close(getatmoption(GetUnderlyingSymbol(), date, optionclass.call));

whereby "date" is pre-defined as any correct expiry date. If I try to retrieve the "next expiry" then I can easily accomplish it with, e.g.:

def price2 = close(getnextExpirationOption(getatmoption(GetUnderlyingSymbol(), date, optionclass.call)));

However, if I try to automate it indefinitely (from the begining to the end of the chart) then I fail misearably. I have tried to to do so with GetDaysToExpiration() as well as simply GetYYYYMMDD(), entering the value as the "date" variable before testing the query with "if isNaN(close(getatmoption(GetUnderlyingSymbol(), date, ......." It doesnt work either!

Do you have a suggestion as to how I could accomplish the following sketch?

def date = getYYYYMMDD;
def shift = 7; ## used to shift the variable "date" into the future

def price = if close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call)) exists
then close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call))
else if close(getatmoption(GetUnderlyingSymbol(), date[-shift], optionclass.call)) doesn't exist
then find the closing price for the next expiry;
Plot xyz = price;

Unsure whether this is possible but I would appreciate any guidance/ help along this line. [FYI, I have looked extensively through the threads related to option handling and I cannot find anything similar to it.]

Many thanks!

i am talking before i try your code, so while it may be obvious on a chart, your words are confusing.
you say you can do it with your price2 formula, then what else do you want?

i don't understand this sentence.
However, if I try to automate it indefinitely (from the begining to the end of the chart) then I fail
 

pontenkin

New member
HI,

Thank you for your reply. Basically, I would like to plot the ATM call option price of the first expiry in the option chain indefinitely. Unfortunately, I can only plot it in the indicator subgraph if I manually set the expiry "date" in:

close(getatmoption(GetUnderlyingSymbol(), date, optionclass.call))

In other words, how can accomplish it automatically so that the price of an ATM call option is plotted (in the indicator sub-graph) and as soon as it expires, the price of the next ATM call option in the option chain is plotted, and so on indefinitely? As a concrete example, let's say the option chain expiry dates are:

..... 1st july, 3rd July, 6th July..... 2nd August, 3rd August, 5th August.....3rd September ....

So, I would like to graph, as an indicator, the price of the ATM call option for e.g. 1st July then once this option expires, the 3rd July ATM call option is plotted, and once it expires then the 6th July and so on without interruptions. This, I cannot accomplish.

As a second goal, I would like to move to, and plot, the next ATM call option 1 or 2 days prior to the expiry.

I am sorry for the confusing description. I hope that this is clearer

Once again, many thanks for your help.
 

halcyonguy

Active member
VIP
HI,

Thank you for your reply. Basically, I would like to plot the ATM call option price of the first expiry in the option chain indefinitely. Unfortunately, I can only plot it in the indicator subgraph if I manually set the expiry "date" in:

close(getatmoption(GetUnderlyingSymbol(), date, optionclass.call))

In other words, how can accomplish it automatically so that the price of an ATM call option is plotted (in the indicator sub-graph) and as soon as it expires, the price of the next ATM call option in the option chain is plotted, and so on indefinitely? As a concrete example, let's say the option chain expiry dates are:

..... 1st july, 3rd July, 6th July..... 2nd August, 3rd August, 5th August.....3rd September ....

So, I would like to graph, as an indicator, the price of the ATM call option for e.g. 1st July then once this option expires, the 3rd July ATM call option is plotted, and once it expires then the 6th July and so on without interruptions. This, I cannot accomplish.

As a second goal, I would like to move to, and plot, the next ATM call option 1 or 2 days prior to the expiry.

I am sorry for the confusing description. I hope that this is clearer

Once again, many thanks for your help.
i think i understand now, thanks for explaining it more.
i have thought about experimenting with similar option formulas, but haven't gotten around to it yet. i will try and look at this, but i'm guessing this will take some time, so it could be a couple weeks till i can start on it, ( till i finish up existing projects)

i don't understand this line,
> As a second goal, I would like to move to, and plot, the next ATM call option 1 or 2 days prior to the expiry.
why plot only 1 or 2 days before ? why not plot all of the price data?

in the mean time, this post might help
https://usethinkscript.com/threads/capture-option-chain-data-via-thinkscript.3871/#post-35695
 

pontenkin

New member
i think i understand now, thanks for explaining it more.
i have thought about experimenting with similar option formulas, but haven't gotten around to it yet. i will try and look at this, but i'm guessing this will take some time, so it could be a couple weeks till i can start on it, ( till i finish up existing projects)

i don't understand this line,

why plot only 1 or 2 days before ? why not plot all of the price data?

in the mean time, this post might help
https://usethinkscript.com/threads/capture-option-chain-data-via-thinkscript.3871/#post-35695
Hi,

Thank you for your reply. I will look into the link.

As far as the "i don't understand this line, ""As a second goal, I would like to move to, and plot, the next ATM call option 1 or 2 days prior to the expiry."" why plot only 1 or 2 days before ? why not plot all of the price data?

If we use the same example: ..... 1st july, 3rd July, 6th July..... 2nd August, 3rd August, 5th August.....3rd September ....

So, I would like to have the option to graph, as an indicator, the price of the ATM call option for e.g. 1st July then 1 (or, eg, 2) days before it expires, the 3rd July ATM call option is plotted, and then 1 (or, eg, 2) days before it expires, then the 6th July ATM call option is plotted and so on without interruptions. It is basically the same concept.

Once again, thank you for reading my question. I realize that my request is rather confusing. If you have any further ideas, please let me know!

:)
 

armeredtech

New member
@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
Do you know how to get this to work on a tick chart? If you do would you plz tell me
 

Similar threads

Top