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