Building a Better Options Flow Indicator

StoneMan

Member
Plus
I am setting out to build an options flow indicator to gather the metrics volume, delta volume (volume of option times its delta), open interest, and open interest delta from the options chain and add them together to gain insights into how the options market is positioned. I am using the scripts from this thread as a bit of inspiration.

https://usethinkscript.com/threads/option-volume-open-interest-indicator-for-thinkorswim.313/page-3

The main improvement I have made to the logic of these scripts is I have found a way to traverse the entire options chain from the initial GetATMOption function in a way that does not require concatenation of any strings or the input of the difference in strikes.

Code:
input ExpirationDate = 20210827;

def vol2ff = if isNaN (volume(GetNextITMOption(GetNextExpirationOption(GetNextExpirationOption (GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL))))))
                then 0
                else volume(GetNextITMOption(GetNextExpirationOption(GetNextExpirationOption (GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL)))));

As you can see, by nesting the get the various GetNext functions you can navigate anywhere you want on the option chain starting from the GetATMOption function. I like to think of the options chain as a grid with GetATMOption being your (0,0) and GetNextOTMOption moving you on the positive X direction, GetNextITMOption moving you in the negative X direction, and GetNextExpiration moving you in the positive Y direction. The code above would return the volume from 2 expirations and one strike in the money out, or (-1, 2) as per the grid. Now I could fill out the grid manually coding each entry by hand but that just seems super inefficient. My question is, is there any way to make this data gathering process more efficient? Like some sort of way to creatively implement a loop to automate this nesting procedure? Matrix math is the first thing that comes to mind but to my knowledge thinkscript does not support arrays so I think I'm screwed there.

Something that helped me organize my thoughts when coming up with this was organizing the options chain by 6 different classifications that correspond with how the Get... functions work. Those are ATMputs, ATMcalls, ITMputs, ITMcalls, OTMputs, OTMcalls. If some sort of matrix math work around can be found it would probably involve looping through all of one class at an expiration then looping that function through the expirations. The user would input limits on how for down the chain and how many expirations out they go. From there just add the totals and you got yourself a robust options flow tool. Any insights from the community would be greatly appreciated.

Cheers and happy trading,

StoneMan
 
@StoneMan The Fold() function could be used for looping... You will most likely find that it won't take look to hit a wall as far as how far you can get with complex data manipulations using Thinkscript... Good luck...
 
Here is my model of the options chain for anyone who wanted a reference. (0,0) is the ATM strike of the option with the nearest expiration. Positive X values are the number of strikes OTM and negative X values are the number of strikes ITM. The Y value is the expiration number.

Code:
-20,0    -20,1    -20,2    -20,3    -20,4    -20,5    -20,6    -20,7
-19,0    -19,1    -19,2    -19,3    -19,4    -19,5    -19,6    -19,7
-18,0    -18,1    -18,2    -18,3    -18,4    -18,5    -18,6    -18,7
-17,0    -17,1    -17,2    -17,3    -17,4    -17,5    -17,6    -17,7
-16,0    -16,1    -16,2    -16,3    -16,4    -16,5    -16,6    -16,7
-15,0    -15,1    -15,2    -15,3    -15,4    -15,5    -15,6    -15,7
-14,0    -14,1    -14,2    -14,3    -14,4    -14,5    -14,6    -14,7
-13,0    -13,1    -13,2    -13,3    -13,4    -13,5    -13,6    -13,7
-12,0    -12,1    -12,2    -12,3    -12,4    -12,5    -12,6    -12,7
-11,0    -11,1    -11,2    -11,3    -11,4    -11,5    -11,6    -11,7
-10,0    -10,1    -10,2    -10,3    -10,4    -10,5    -10,6    -10,7
-9,0    -9,1    -9,2    -9,3    -9,4    -9,5    -9,6    -9,7
-8,0    -8,1    -8,2    -8,3    -8,4    -8,5    -8,6    -8,7
-7,0    -7,1    -7,2    -7,3    -7,4    -7,5    -7,6    -7,7
-6,0    -6,1    -6,2    -6,3    -6,4    -6,5    -6,6    -6,7
-5,0    -5,1    -5,2    -5,3    -5,4    -5,5    -5,6    -5,7
-4,0    -4,1    -4,2    -4,3    -4,4    -4,5    -4,6    -4,7
-3,0    -3,1    -3,2    -3,3    -3,4    -3,5    -3,6    -3,7
-2,0    -2,1    -2,2    -2,3    -2,4    -2,5    -2,6    -2,7
-1,0    -1,1    -1,2    -1,3    -1,4    -1,5    -1,6    -1,7
 0,0     0,1     0,2     0,3     0,4     0,5     0,6    0,7
 1,0     1,1     1,2     1,3     1,4     1,5     1,6    1,7
 2,0     2,1     2,2     2,3     2,4     2,5     2,6    2,7
 3,0     3,1     3,2     3,3     3,4     3,5     3,6    3,7
 4,0     4,1     4,2     4,3     4,4     4,5     4,6    4,7
 5,0     5,1     5,2     5,3     5,4     5,5     5,6    5,7
 6,0     6,1     6,2     6,3     6,4     6,5     6,6    6,7
 7,0     7,1     7,2     7,3     7,4     7,5     7,6    7,7
 8,0     8,1     8,2     8,3     8,4     8,5     8,6    8,7
 9,0     9,1     9,2     9,3     9,4     9,5     9,6    9,7
10,0    10,1    10,2    10,3    10,4    10,5    10,6    10,7
11,0    11,1    11,2    11,3    11,4    11,5    11,6    11,7
12,0    12,1    12,2    12,3    12,4    12,5    12,6    12,7
13,0    13,1    13,2    13,3    13,4    13,5    13,6    13,7
14,0    14,1    14,2    14,3    14,4    14,5    14,6    14,7
15,0    15,1    15,2    15,3    15,4    15,5    15,6    15,7
16,0    16,1    16,2    16,3    16,4    16,5    16,6    16,7
17,0    17,1    17,2    17,3    17,4    17,5    17,6    17,7
18,0    18,1    18,2    18,3    18,4    18,5    18,6    18,7
19,0    19,1    19,2    19,3    19,4    19,5    19,6    19,7
20,0    20,1    20,2    20,3    20,4    20,5    20,6    20,7
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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