Pull Underlying symbol from the options ticker symbol


Category:
0
0

I have a scanner from a friend that scans for specific options that meet a few criteria and then of course sends them to a watch list.  The list has the option specific ticker instead of the underlying stock symbol…for example   UBER200207C33   What I would like to do is automatically run that list through another scanner for financials criteria or other studies.  The issue of course is you can’t scan option symbols like that …  is there a way within TOS to take a list like that and have it know that it is UBER and scan the main ticker for the new criteria?  Sorry if I am not explaining myself very well

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 11, 2020 4:56 pm
1022 views
0
Private answer

There is a function within the Thinkorswim language which enables us to pull the underlying ticker symbol. However I'm not sure how you plan to use this so all I can do is provide an example which displays the underlying symbol in a custom watchlist column:

AddLabel(yes, GetUnderlyingSymbol(), Color.CURRENT);

So the key to this is the function named GetUnderlyingSymbol().

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

This function returns a string value. This mean we cannot assign the output of that function to any variables. You can only use it within other functions which take a string input parameter for 'symbol'. Here is another example which would display the current price of the underlying ticker symbol in a custom watchlist column:

plot data = close(symbol = GetUnderlyingSymbol());

You can also assign that to a variable:

def closeOfUnderlying = close(symbol = GetUnderlyingSymbol());

This will enable you to use the close of the underlying ticker symbol elsewhere in your code.

If you wanted to take that list of ticker symbols from the first example and use that as the foundation for another scan. You would need to export that to a .csv file where you can extract your ticker symbols and import them into a new personal watchlist.

Again, you left out the most important details of your specifications. Which is what scan you wanted to run against this list of OPRA codes. You could take that original watchlist of OPRA codes and run the follow scan directly:

def closeOfUnderlying = close(symbol = GetUnderlyingSymbol());
plot scan = closeOfUnderlying > 10.0;

This technique will work with all the fundamental data elements of the chart: Open, High, Low, Close, Volume etc... A complete list can be found here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/FundamentalType

So yes, with a bit of creativity you can compute just about any of the technical indicators within your scan. Converting the OPRA codes into underlying ticker symbols, assigning each to a variable and then use those variables to compute the indicator.

For example you can compute the ATR study like this:

input length = 14;
input averageType = AverageType.WILDERS;
def closeOfUnderlying = close(symbol = GetUnderlyingSymbol());
def highOfUnderlying = high(symbol = GetUnderlyingSymbol());
def lowOfUnderlying = low(symbol = GetUnderlyingSymbol());
plot ATR = MovingAverage(averageType, TrueRange(highOfUnderlying, closeOfUnderlying, lowOfUnderlying), length);

Be sure to test individual components of your scan before going all out and writing the full script. This may have some bugs when running scans while the options market is closed. Can't do anything about that.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on January 12, 2020 12:31 pm
0
Thank you for the detailed answer...that does help....basically financial scans of the underlying ....just a starting point...may add more .... and this helps greatly! thank you
( at January 12, 2020 1:49 pm)