Options Gamma Study For ThinkOrSwim

Would it be possible to take the code below that I have on the options chain and build a lower study that would show the change in gamma for the highlighted Strikes for 0DTE? Even if I had to change the date each day in the code to get it to pull the data? I would want this for SPX and SPY so I could see change in gamma on the chart without having to open up the options chain. I view this every day to get an idea of the gamma wall that may be support or resistance. What I have noticed is that on the SPX if gamma is call heavy then it most likely goes up and those strikes are ITM at end of day. And on SPY just the opposite. Seems to be more of a contrarian indicator on SPY and a direction on SPX. But only 0DTE matters.

CODE
# Gamma Exposure at each strike is calculated by the formula option gamma * open interest * 100 (calls, x-100 for puts)

plot data = if IsPut() then gamma() * -100 * open_interest() else gamma() * 100 * open_interest();
assignbackgroundcolor(if AbsValue(data) > 2000 then createcolor(250,150,100) else color.black);
data.assignvaluecolor(if AbsValue(data) > 2000 then color.black else color.current);
15176[/ATTACH]']
Ua5aYVo.jpg
 

Attachments

  • Ua5aYVo.jpg
    Ua5aYVo.jpg
    448.8 KB · Views: 847
Ok, I think I got it to work as there are numbers showing now. To do so, I restarted TOS and followed the steps to add the code to a custom column, but I did this before adding the column to my current layout. Adding the column to the layout, then adding the code to the column doesn't seem to work.
 
Its possible that it wont work till tomorrow open. Not sure it will pull data after close. Because it only updates after the open and through the day. Everything looks right. I'm no code guy. Wish I was. I want to have 3 levels colored yellow, orange and red. The > than 2000 is great for SPX but on SPY you need > 100000 and > 200000. I use it as a way to sell options. So right now I have three columns on my chain. It works but not a clean as I would like.
And what numbers are associated with the colors, if you don't mind my asking?
 
Ok, I think I got it to work as there are numbers showing now. To do so, I restarted TOS and followed the steps to add the code to a custom column, but I did this before adding the column to my current layout. Adding the column to the layout, then adding the code to the column doesn't seem to work.
And what numbers are associated with the colors, if you don't mind my asking?
Look at the code - the value of 2000 highlights the corresponding strike.
 
If you don't want to switch back and forth to the TOS Trade tab you can use the DDE function in either OpenOffice Calc or Excel to display it all there in a spreadsheet. That's what I did. The numbers are slightly different, but the highlighted strikes are the same.
 
Its possible that it wont work till tomorrow open. Not sure it will pull data after close. Because it only updates after the open and through the day. Everything looks right. I'm no code guy. Wish I was. I want to have 3 levels colored yellow, orange and red. The > than 2000 is great for SPX but on SPY you need > 100000 and > 200000. I use it as a way to sell options. So right now I have three columns on my chain. It works but not a clean as I would like.

Is this sorta what you're looking for?
Code:
plot data = if IsPut() then gamma() * -100 * open_interest() else gamma() * 100 * open_interest();

assignbackgroundcolor(if AbsValue(data) >= 20000 then color.red else if AbsValue(data) >= 10000 then color.yellow else if AbsValue(data) >= 2000 then createcolor(250,150,100) else color.black);

data.assignvaluecolor(if AbsValue(data) > 2000 then color.black else color.current);
 
Is this sorta what you're looking for?
Code:
plot data = if IsPut() then gamma() * -100 * open_interest() else gamma() * 100 * open_interest();

assignbackgroundcolor(if AbsValue(data) >= 20000 then color.red else if AbsValue(data) >= 10000 then color.yellow else if AbsValue(data) >= 2000 then createcolor(250,150,100) else color.black);

data.assignvaluecolor(if AbsValue(data) > 2000 then color.black else color.current);
I will check it out tomorrow and let you know. I'm trying to color them different to tell the differance between the winners and losers on 0DTE. Gamma can hurt you bad on 0DTE if you are wrong. I have been having good success with my testing at <2000 SPX Thanks
 
Here is the tos script directly from OptionGamma study

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#

declare lower;
plot gamma = gamma();
gamma.SetDefaultColor(GetColor(0));
 
GEX options strike

this code is meant to give you the GEX for a particular options strike. credit to nextsignals, he posted the code here

why is it displaying NaN instead of the actual GEX value? and how to fix it?

any help is appreciated. thank you in advance

Code:
#Gamma exposure at each strike formula:
# option gamma * open interest * 100 (call, x-100 for puts)

plot gex = if isput() then ceil(gamma() * -100 * open_interest()) else ceil(gamma() * 100 * open_interest());
 
Last edited by a moderator:
All mine customized tabs were used, I deleted one and used that... I just put this in on Saturday, and all I get is NaN. .. Well, this morning, I'm still getting NaN I'm so confused. I am looking at the SPX, the SPY and nothing but NaN. I renamed it, double-checked the script, I have it on "D" for day... what am I missing?

Thanks !
 
Last edited:
All mine customized tabs were used, I deleted one and used that... I just put this in on Saturday, and all I get is NaN. .. Well, this morning, I'm still getting NaN I'm so confused. I am looking at the SPX, the SPY and nothing but NaN. I renamed it, double-checked the script, I have it on "D" for day... what am I missing?

Thanks !
plot data = if IsPut() then gamma() * -100 * open_interest() else gamma() * 100 * open_interest();
assignbackgroundcolor(if AbsValue(data) > 2000 then color.orange else color.black);
data.assignvaluecolor(if AbsValue(data) > 2000 then color.black else color.current);

http://tos.mx/WO7InGs
d5Y7SHX.png
 
Last edited:
plot data = if IsPut() then gamma() * -100 * open_interest() else gamma() * 100 * open_interest();
assignbackgroundcolor(if AbsValue(data) > 2000 then color.orange else color.black);
data.assignvaluecolor(if AbsValue(data) > 2000 then color.black else color.current);

http://tos.mx/WO7InGs
d5Y7SHX.png
How is this code any different than the other? They look exactly the same? I just downloaded it, it didn't show up in my "Available Items" because all my customized ones are used. I deleted one and renamed it, copied and pasted the script and I have the same problem... help, please?
 
How is this code any different than the other? They look exactly the same? I just downloaded it, it didn't show up in my "Available Items" because all my customized ones are used. I deleted one and renamed it, copied and pasted the script and I have the same problem... help, please?
Hi bro, please remember to set to "daily" timeframe. Alternatively, you can use one of your previous script (in daily frame) and paste the scripts and rename it. Usually, it will work when u used the previously scripts in daily timeframe.

 

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