0 DTE option flow for SPX (WIP)

ChocolateVol

New member
see code fix in next post
Hi, I'm stuck with this script. Syntax appears to be right but for some reason I cant figure out why its not working. Issue is popping up at the ATM_option line.

My goal is to track the intraday 0 DTE option volume for ATM calls and puts for SPX and SPY that are within the daily market maker's expected move (using the prior day's VIX close).

Once I can make it work for SPX calls I want to replicate for SPY and also use it on PUTS in a lower study or as an inverted negative histogram in the same plot.
I'm trying to track institutional buying/selling pressure (hence the threshold for size).

When the script is valid, ideally I want to explore beyond volume to track premium (price*volume) and gamma.

This on itself would ultimately always be a bias confirmation not an isolated trading signal.
 
Last edited by a moderator:
Solution
This study is great, thanks to all in this thread sharing.

One question, I am unable to get SPX premiums to display (even if my upper chart is SPY or /ES), I have also tried using SPXW as ticker as done with other scripts in this thread. Any idea why this isn't working?

Try this:
set show extended hours to off

Code:
# Run on 1 min chart only.  Calculates Premium. ( 1 min volume x 1 min OHLC4)
# Starts at 945. First 15 min lots of chaos and false signals.

declare lower;
declare once_per_bar;

input chain_width = 5;
input symbol = "SPXW"; #"SPXW"
input premium_extreme = 1000000;

def after945 = SecondsFromTime(945) >= 0;

def vix = close("VIX", AggregationPeriod.DAY)[1];
#def price = round(close(symbol...
For some reason the script didn't work yesterday. I tried setting time interval to Today, turning off the extended hours, etc. I am not sure what causes the script to work on some days and not on hours.

Is there some way to identify what causes this to happen? Also is there the option to cycle between multiple tickers (e.g., SPY, SPX, QQQ, etc) from a drop down menu vs modifying the script manually?

Thank you experts for your input and help, it has been amazing!
Here is the luxury version of what you guys are trying to do.. I think... I have been working on this for over 10 months now. I call it Enigma script. for zero days when you see peaks, it tells you turnaround most of the time. (Non trending days, success rate is high.. in trending days not reliable)
For spy, qqq iwm and all stocks. Whatever the chart is it plots call put executions of that ticker. If you use it for stocks, dont forget to set date manual and select expiration days.

Auto date, auto strike and plots $$$ amount executed for each strike listed based on OHLC4 price.
If you select autodate it shows 0DTE, if you choose offset as 1, it shows 1DTE. It knows weekends but not special holidays. Keep averagelines autosignal as no.. it is experimental. Aggregation period must stay in DAY too. It scans itm atm and otm calls and optyions and determines the strikes by itself. I think strike selection is 95-96% correct. It does not work for SPX, ES and NQ.
https://tos.mx/eMwmvB7
I typically use it like this :
1691991121972.png
Below version only works for SPX, ES and NQ: it is chart independent. for ES and NQ, you have to input prefix.
https://tos.mx/8ciIDG9

If you guys come up with more statistical alert etc instead of fixed value alert for extreme please let me know.
Enjoy the scripts.
 
Here is the luxury version of what you guys are trying to do.. I think... I have been working on this for over 10 months now. I call it Enigma script. for zero days when you see peaks, it tells you turnaround most of the time. (Non trending days, success rate is high.. in trending days not reliable)
For spy, qqq iwm and all stocks. Whatever the chart is it plots call put executions of that ticker. If you use it for stocks, dont forget to set date manual and select expiration days.

Auto date, auto strike and plots $$$ amount executed for each strike listed based on OHLC4 price.
If you select autodate it shows 0DTE, if you choose offset as 1, it shows 1DTE. It knows weekends but not special holidays. Keep averagelines autosignal as no.. it is experimental. Aggregation period must stay in DAY too. It scans itm atm and otm calls and optyions and determines the strikes by itself. I think strike selection is 95-96% correct. It does not work for SPX, ES and NQ.
https://tos.mx/eMwmvB7
I typically use it like this :
View attachment 19490 Below version only works for SPX, ES and NQ: it is chart independent. for ES and NQ, you have to input prefix.
https://tos.mx/8ciIDG9

If you guys come up with more statistical alert etc instead of fixed value alert for extreme please let me know.
Enjoy the scripts.
Amazing! I am going to test it out this week, thanks for being as so kind as to share your hard work, greatly appreciate it!
 
Here is the luxury version of what you guys are trying to do.. I think... I have been working on this for over 10 months now. I call it Enigma script. for zero days when you see peaks, it tells you turnaround most of the time. (Non trending days, success rate is high.. in trending days not reliable)
For spy, qqq iwm and all stocks. Whatever the chart is it plots call put executions of that ticker. If you use it for stocks, dont forget to set date manual and select expiration days.

Auto date, auto strike and plots $$$ amount executed for each strike listed based on OHLC4 price.
If you select autodate it shows 0DTE, if you choose offset as 1, it shows 1DTE. It knows weekends but not special holidays. Keep averagelines autosignal as no.. it is experimental. Aggregation period must stay in DAY too. It scans itm atm and otm calls and optyions and determines the strikes by itself. I think strike selection is 95-96% correct. It does not work for SPX, ES and NQ.
https://tos.mx/eMwmvB7
I typically use it like this :
View attachment 19490 Below version only works for SPX, ES and NQ: it is chart independent. for ES and NQ, you have to input prefix.
https://tos.mx/8ciIDG9

If you guys come up with more statistical alert etc instead of fixed value alert for extreme please let me know.
Enjoy the scripts.
Has been working without fail daily and very helpful! Do you combine it with any other indicators? Trading on 1 min time frame?
 
Here is the luxury version of what you guys are trying to do.. I think... I have been working on this for over 10 months now. I call it Enigma script. for zero days when you see peaks, it tells you turnaround most of the time. (Non trending days, success rate is high.. in trending days not reliable)
For spy, qqq iwm and all stocks. Whatever the chart is it plots call put executions of that ticker. If you use it for stocks, dont forget to set date manual and select expiration days.

Auto date, auto strike and plots $$$ amount executed for each strike listed based on OHLC4 price.
If you select autodate it shows 0DTE, if you choose offset as 1, it shows 1DTE. It knows weekends but not special holidays. Keep averagelines autosignal as no.. it is experimental. Aggregation period must stay in DAY too. It scans itm atm and otm calls and optyions and determines the strikes by itself. I think strike selection is 95-96% correct. It does not work for SPX, ES and NQ.
https://tos.mx/eMwmvB7
I typically use it like this :
View attachment 19490 Below version only works for SPX, ES and NQ: it is chart independent. for ES and NQ, you have to input prefix.
https://tos.mx/8ciIDG9

If you guys come up with more statistical alert etc instead of fixed value alert for extreme please let me know.
Enjoy the scripts.
Can you give an example of how to use this set up? I had manual date as 2023-10-16 for MSFT and it shows nothing on the bottom.
 
@2187Nick is right. I also use the same concept and run the script on SPY etc. Please see below where I took both scripts above and merged relevant concepts. This should show both put/call volumes.

Rich (BB code):
declare lower;
declare once_per_bar;

input days = 1;
input chain_width = 5;
input threshold = 50;
input symbol = "SPXW";

def vix = close("VIX", AggregationPeriod.DAY)[1];
def SPX_1 = close("SPX", AggregationPeriod.DAY)[1];


def move = vix / Sqrt(252 / days) / 100;
def strike_up = Round (SPX_1 * (1 + move) / chain_width, 0.01) * chain_width;
def strike_down =  Round (SPX_1 * (1 - move) / chain_width, 0.01) * chain_width;

#get total call option volumes around the ATM strikes that are within the expected daily move

# get ATM strike
def ATM_Strike = Round (SPX_1 / chain_width, 0.01) * chain_width;

# get 0DTE expiration
def CurrentYear = GetYear()-2000;
def CurrentMonth = GetMonth();
def CurrentDay = GetDayOfMonth(GetYYYYMMDD());
def DateString = CurrentYear * 10000 + CurrentMonth * 100 + CurrentDay;

#AddLabel(yes, AsPrice(DateString));
#AddLabel(yes, "Spx_close" + strike_up + " " + strike_down  );

#define option series code


def Call_Volume = fold strike_c = ATM_Strike to strike_up with v do v +
                if IsNaN(volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c))) then 0
                else if threshold > volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c)) then 0
                else volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c));

def Put_Volume = fold strike_p = ATM_Strike to strike_up with v_p do v_p +
                if IsNaN(volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p))) then 0
                else if threshold > volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p)) then 0
                else volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p));



plot test = Call_Volume;
test.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
test.AssignValueColor(if Call_Volume > 1000 then Color.GREEN else Color.DARK_GRAY);

plot test_2 = -1.0 * put_Volume; #show below zero for display purposes
test_2.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
test_2.AssignValueColor(if put_Volume > -1.0 * 1000 then Color.RED else Color.DARK_GRAY);


How do you make this work for SPY or QQQ?
 
Here is the luxury version of what you guys are trying to do.. I think... I have been working on this for over 10 months now. I call it Enigma script. for zero days when you see peaks, it tells you turnaround most of the time. (Non trending days, success rate is high.. in trending days not reliable)
For spy, qqq iwm and all stocks. Whatever the chart is it plots call put executions of that ticker. If you use it for stocks, dont forget to set date manual and select expiration days.

Auto date, auto strike and plots $$$ amount executed for each strike listed based on OHLC4 price.
If you select autodate it shows 0DTE, if you choose offset as 1, it shows 1DTE. It knows weekends but not special holidays. Keep averagelines autosignal as no.. it is experimental. Aggregation period must stay in DAY too. It scans itm atm and otm calls and optyions and determines the strikes by itself. I think strike selection is 95-96% correct. It does not work for SPX, ES and NQ.
https://tos.mx/eMwmvB7
I typically use it like this :
View attachment 19490 Below version only works for SPX, ES and NQ: it is chart independent. for ES and NQ, you have to input prefix.
https://tos.mx/8ciIDG9

If you guys come up with more statistical alert etc instead of fixed value alert for extreme please let me know.
Enjoy the scripts.
What you have to determine is related to volatility smile.

1st: Is the option(s) in the pink spike you see being bought/sold. That is tough to determine.
If the option's Implied Volality(IV) is above the MMs(market maker) then they or a large options dealer are selling, if below, they buy. But plotting a Volatility surface (or smile/smirk) is not easy.

2nd: and more simply - the options chains has 4 quadrants, not 2. This is how it works - Lower strike prices have higher IV. That means itm Calls and otm Put sits Calls have the same volatility. That also means, otm Calls and itm Puts have the same IV. The out of the money are speculative (both directions) and the in the money are hedging (both directions). And this is important: But...their Implied Volatile affects the total Volatility Smile of the underlying differently.

SO you have to break it up into quadrant. ITM Calls & OTM Puts affects the moves the same (more volatility), underlying price goes down.

And ITM Puts & OTM Calls move the same. (less volatility), underlying goes up.

Add each quadrant together. The net is the direction the MMs/ODs expect to take it. Use Get (Gexbot or SpotGamma) to draw your zero gamma levels on the chart, wait for the inversion signals and voila.
 
@2187Nick is right. I also use the same concept and run the script on SPY etc. Please see below where I took both scripts above and merged relevant concepts. This should show both put/call volumes.

Rich (BB code):
declare lower;
declare once_per_bar;

input days = 1;
input chain_width = 5;
input threshold = 50;
input symbol = "SPXW";

def vix = close("VIX", AggregationPeriod.DAY)[1];
def SPX_1 = close("SPX", AggregationPeriod.DAY)[1];


def move = vix / Sqrt(252 / days) / 100;
def strike_up = Round (SPX_1 * (1 + move) / chain_width, 0.01) * chain_width;
def strike_down =  Round (SPX_1 * (1 - move) / chain_width, 0.01) * chain_width;

#get total call option volumes around the ATM strikes that are within the expected daily move

# get ATM strike
def ATM_Strike = Round (SPX_1 / chain_width, 0.01) * chain_width;

# get 0DTE expiration
def CurrentYear = GetYear()-2000;
def CurrentMonth = GetMonth();
def CurrentDay = GetDayOfMonth(GetYYYYMMDD());
def DateString = CurrentYear * 10000 + CurrentMonth * 100 + CurrentDay;

#AddLabel(yes, AsPrice(DateString));
#AddLabel(yes, "Spx_close" + strike_up + " " + strike_down  );

#define option series code


def Call_Volume = fold strike_c = ATM_Strike to strike_up with v do v +
                if IsNaN(volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c))) then 0
                else if threshold > volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c)) then 0
                else volume("." + symbol +  AsPrice(DateString) + "C" + AsPrice(strike_c));

def Put_Volume = fold strike_p = ATM_Strike to strike_up with v_p do v_p +
                if IsNaN(volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p))) then 0
                else if threshold > volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p)) then 0
                else volume("." + symbol +  AsPrice(DateString) + "P" + AsPrice(strike_p));



plot test = Call_Volume;
test.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
test.AssignValueColor(if Call_Volume > 1000 then Color.GREEN else Color.DARK_GRAY);

plot test_2 = -1.0 * put_Volume; #show below zero for display purposes
test_2.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
test_2.AssignValueColor(if put_Volume > -1.0 * 1000 then Color.RED else Color.DARK_GRAY);


Good morning! Would you happen to know why this indicator no longer works? I ran it on a lower 5min chart of spy with extended hours off and all i get is a black screen n/a
 
What you have to determine is related to volatility smile.

1st: Is the option(s) in the pink spike you see being bought/sold. That is tough to determine.
If the option's Implied Volality(IV) is above the MMs(market maker) then they or a large options dealer are selling, if below, they buy. But plotting a Volatility surface (or smile/smirk) is not easy.

2nd: and more simply - the options chains has 4 quadrants, not 2. This is how it works - Lower strike prices have higher IV. That means itm Calls and otm Put sits Calls have the same volatility. That also means, otm Calls and itm Puts have the same IV. The out of the money are speculative (both directions) and the in the money are hedging (both directions). And this is important: But...their Implied Volatile affects the total Volatility Smile of the underlying differently.

SO you have to break it up into quadrant. ITM Calls & OTM Puts affects the moves the same (more volatility), underlying price goes down.

And ITM Puts & OTM Calls move the same. (less volatility), underlying goes up.

Add each quadrant together. The net is the direction the MMs/ODs expect to take it. Use Get (Gexbot or SpotGamma) to draw your zero gamma levels on the chart, wait for the inversion signals and voila.
I thought gexbot and spotgamma requires subscription to see zero gamma level, isn't it?
 

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