Hi everyone. I added this script
https://usethinkscript.com/threads/implied-move-based-on-weekly-options-for-thinkorswim.1449/
and It has a weird impact on all charts on TOS. The script is loaded to a separate chart that only has labels on it (no candles) but is impacts every chart on the system.
Once you load the script, all charts glitch/get stuck terribly, the Active trader works fine but the charts do not follow the price.
The script is made by Mobius, but I made some changes in order to get what I need from it. Apparently, I did something that messes up everything, but I don't know what. Please take a look and let me know.
What I want from the script is to detect and just show me the ATM Call, ATM Put and ATM straddle prices in labels. It does that successfully, but the tradeoff is the charts issue.
Please let me know how I can fix this.
Thank you
https://usethinkscript.com/threads/implied-move-based-on-weekly-options-for-thinkorswim.1449/
and It has a weird impact on all charts on TOS. The script is loaded to a separate chart that only has labels on it (no candles) but is impacts every chart on the system.
Once you load the script, all charts glitch/get stuck terribly, the Active trader works fine but the charts do not follow the price.
The script is made by Mobius, but I made some changes in order to get what I need from it. Apparently, I did something that messes up everything, but I don't know what. Please take a look and let me know.
What I want from the script is to detect and just show me the ATM Call, ATM Put and ATM straddle prices in labels. It does that successfully, but the tradeoff is the charts issue.
Please let me know how I can fix this.
Thank you
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 ATMPprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)))
then ATMPprice[1]
else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT));
DEF ATMSTRADDLE = ATMCprice + ATMPprice;
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:" +
GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL) +
" Price = $" + ATMCprice, color.dARK_ORANGE);
AddLabel(show_label and IsOptionable(), "ATM Put:" +
GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.Put) +
" Price = $" + ATMPprice, color.darK_ORANGE);
AddLabel(show_label and IsOptionable(), "ATM Straddle:" + ATMSTRADDLE
, color.darK_ORANGE);
# End Code Weekly Optionsplot Data = close
Last edited by a moderator: