Options Vol/Open Interest For ThinkOrSwim

One way of getting the Ratio value between Option Volume and Open Interest for any option-strike, for any stocks in any watchlist is to download any pertinent scanned data into an Excel worksheet; which among other things, calculates in real time the Ratio.

You can add filters to the Excel sheet to sort the pertinent Ratio column to see which stocks/options/strikes are being favored.
You can add other Excel spreadsheet filters to select CALLs or PUTs and even expiration dates.

The only disadvantage of this approach is your scan-columns-layout would be rigid conflicting with other layouts you may have. In other words, if you already have a scan-column-layout showing columns A,B,C and D for any other purpose and now you need to add a new column F, your existing scan-column-layout has now an extra column which may conflict with previous 'viewing' analysis.

To that effect, recommend:
  • creating a ''a standard layout'' with all the columns you may need,
  • download the data into Excel - in Realtime - to do the number-crunching if ToS can't do it for you via Studies.
  • Out of the scan results, you can select to ''Export into Excel'' from the menu. Hope it helps.
 
Last edited by a moderator:
Hello,

I've been trying to create a script that looks at options data.

When I attempt to get the volume related to a specific option, I've been getting inconsistent results and I'm not sure why. I've used some hard coded values that would work and I've also used dynamically pulled values that would also work, but only sometimes. Within the same day, minutes apart even, I would lose my dynamic data and I'm finding today that I can't even pull the static data.

Here's an example of static data that I'm trying to pull into a label:
Code:
AddLabel(
        1,
        concat("option: ", GetATMOption("SPY", 20211025, optionType = OptionClass.CALL)),
        Color.LIGHT_ORANGE
        );
This does not provide an option name. If I update the date number to be the 26th of October 2021 then it works to pull the call option for the 25th, I still don't understand this.

Now when I want to pull data on the volume of an option I get nothing as well:
Code:
AddLabel(
        yes,
        Concat("Today's Total Volume = ", volume(
                    ".SPY211025C456",
                    AggregationPeriod.DAY)),
        color.orange
        );

Can anyone help me out here? Sometimes it works and sometimes it doesn't, all within minutes of each other.
 
Shot in the dark but does anyone know of a way to find out if an option call or put is being sold or purchased on TOS?
If I understand correctly your question, you can expand the Options Time and Sales (below Option Chain tab, if not there, selected off the menu) and look at the coloring. Each transaction is highlighted in two colors, plus no-coloring. Green means a ''Buy'', Red is a ''Sell'' and non-colored means ''In-between'' market prices. Those non-colored are difficult to tell the trader intention unless you look deeply at the transacted price. And with so many ''transactions'' (long tape) to check, it becomes a little tough to get closer to the overall bearishness or bullishness for the day. An Excel worksheet would help a lot tabulating the results and thru a Pivot table, you can tell bearishness or bullishness of today's activity. The Open Interest in PUTs or CALLs is no indication of bullishness or bearishness. Only on-going accumulation of daily transactions could get you closer to the real ''breath''.
 
Pieced this together with other scripts. It seems to work and matches the volume label off a options hacker scan. Good Luck

Code:
#OPTION_VOLUME
def dailyvolume = volume(period = "DAY");
addLabel(dailyvolume, "Volume = " +(round(dailyvolume,0)+ ""), Color.WHITE);
 
#OPTION_VOLUME def dailyvolume = volume(period = "DAY"); addLabel(dailyvolume, "Volume = " +(round(dailyvolume,0)+ ""), Color.WHITE);
Hey!

Thanks for the feedback. This does work nicely however I don't think it solves the issue I'm having above. When I attempt to get the volume of an option (using SPY in this example) I get no returned value.

I do think I found the issue however. Let's say I'm looking at SPY and I want the ATM option, the function is as follows:
GetATMOption ( String underlyingSymbol, int yyyyMmDd, String optionType);

When entering the date for the option .SPY211029C456, an option expiring 10/29/2021 as it is dated in the name and falls under that option chain, I have to provide a date of 10/30/2021, a day later. I guess this is because it technically expires at the 30th.

Anyway, I believe that's where my issue was coming from!
 
@douglass - If you wish to see the volume for a contract, click on the layout tab (Customize) Volume (Add item) ...or simply click the preset Volume, Open Interest. GL

jfIvn8C.png
 
Hey!

Thanks for the feedback. This does work nicely however I don't think it solves the issue I'm having above. When I attempt to get the volume of an option (using SPY in this example) I get no returned value.

I do think I found the issue however. Let's say I'm looking at SPY and I want the ATM option, the function is as follows:
GetATMOption ( String underlyingSymbol, int yyyyMmDd, String optionType);

When entering the date for the option .SPY211029C456, an option expiring 10/29/2021 as it is dated in the name and falls under that option chain, I have to provide a date of 10/30/2021, a day later. I guess this is because it technically expires at the 30th.

Anyway, I believe that's where my issue was coming from!
Great work Douglass. I was having this same problem and came across your post. A very frustrating problem and I'm not sure why your solution seems to work. Experimenting, putting the date as Expiration Date + 1 did produce some data for monthly SPX options but not for weekly, where I have yet to be able to pull any data w this function no matter how much I mess around with it. Like many functions related to options on TOS, getatmoption seems to leave a lot to be desired both in function and documentation. I'm not sure how you figured out a hack for it but thank you.
 
Last edited:
Hello,

I would like to create a custom scan for option contract volume over multiple time frames from 9:30 - 16:00.

Tomsk, wrote this script which yields results, but the volume data is based on the common underlying stock not the option contract volume.
Code:
# Volume RTH First 30 Mins
# tomsk
# 11.5.2019

declare hide_on_daily;
input startTime = 0930;
input endTime = 1000;

def Active = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
def Vol30Mins = if Active and !Active[1] then volume
                else if Active then Vol30Mins[1] + volume
                else Vol30Mins[1];
AddLabel(1, "Volume First 30 Mins = " + Vol30Mins, Color.YELLOW);
# End Volume RTH First 30 Mins

Is there a way to differentiate between the two (common versus option) plus add a second filter for contract volume?

For example:
Contract Volume from 09:30 – 10:30 >= 2000
Contract Volume from 09:30 – 12:00 >= 5000
Contract Volume from 09:30 – 14:00 >= 7500

Thank you, any help is appreciated.
 
Assuming this still holds true, I am out of luck.

"The ToS Options Hacker Module doesn't allow the using of custom scripts to scan against options related data.
Your scan requests can't be scripted into the scanner." ~MerryDay
 
I would like a scanner that scans for highest %change in options volume and open interest.traded comparing to 5 minutes ago or time X ago.

Asking to see the change quickly to get on these trades like BBBY today,

"""$BBBY announces deal with $KR.

News came after market closed.

Of course 5 minutes before close, 3,526 contracts were traded on OTM calls, shadowing historical avg. vol."""""
 
I would like a scanner that scans for highest %change in options volume and open interest.traded comparing to 5 minutes ago or time X ago.

Asking to see the change quickly to get on these trades like BBBY today,

"""$BBBY announces deal with $KR.

News came after market closed.

Of course 5 minutes before close, 3,526 contracts were traded on OTM calls, shadowing historical avg. vol."""""
https://usethinkscript.com/threads/option-volume-open-interest-for-thinkorswim.313/#post-75449

See the above link. Read through all 8 pages will provide an understanding of what is and what is not possible.
 
Last edited:
HELP WITH CODE PLEASE.
in the options chain you can create custom list and actually apply formulas. I tried this formula without the 'if' statement but notices that if
volume()[0] is zero i would get strange values. Sometimes it would substitute Volume()9[1] into the formula for Volume()[0] if it was 0.
"if' statements TOS i find confusing. I tried this but still get strange values when volume()[0] is zero.
plot THIS =if (volume()[0] !=0, ( volume()[0] / volume()[1])*100,0);
or
plot THIS =if (volume()[0] >0, ( volume()[0] / volume()[1])*100,0);
its finding another value for volume()[0] when its zero and not returning zero.
 
Shot in the dark but does anyone know of a way to find out if an option call or put is being sold or purchased on TOS?
well it would be,Calls traded at Ask = Green
Puts traded at Bid = Green

Calls traded at bid = Red
Puts traded at ask = Red.

Now the question is how to take this data and plot this.
 
Ruby:
# Option Volume/Open Interest Indicator
# NPTrading : modified script provided by DeusMecanicus in Post #21
# NPTrading : AsPrice function used to support stock price in 4 digits
# NPTrading : optionSeriesPrefix is the option expiry date in format YYMMDD. This Expiry date can be determined automatically (for monthly and weekly options both )but as of now it is manual modification.
# NPTrading : Strike price determined based on current close price but could be previous day close
# NPTrading : Script is work in progress, shared as requested for other to use and modify as per their need
# NPTrading : please read comments in the script


declare lower;
input optionSeriesPrefix = "210611"; #NPTrading : manually update option expiry date in format YYMMDD
input strikeSpacing = { ".5", "1", "2.5", "5", default "10", "25" }; #default 10 for large price stock


#NPTrading : Strike price determined based on current close price but could be previous day close
def PutStrike = Floor(close/10)*10;
def CallStrike = Floor(close/10)*10;


AddLabel(1, GetSymbol() + " Exp:" + optionSeriesPrefix + " CStrike:" + CallStrike + " PStrike:" + PutStrike , Color.WHITE);


input ShowAllLabels = no;
input Showput = no;
input Showput1 = no;
input Showput2 = no;
input Showput3 = no;
input Showput4 = no;
input Showput5 = no;
input Showput6 = no;
input Showput7 = no;
input Showput8 = no;
input Showput9 = no;
input Showput10 = no;
input Showput11 = no;
input Showput12 = no;
input Showput13 = no;
input Showput14 = no;
input Showput15 = no;
input Showput16 = no;
input Showput17 = no;
input Showput18 = no;
input Showput19 = no;
input Showput20 = no;

input Showcall = no;
input Showcall1 = no;
input Showcall2 = no;
input Showcall3 = no;
input Showcall4 = no;
input Showcall5 = no;
input Showcall6 = no;
input Showcall7 = no;
input Showcall8 = no;
input Showcall9 = no;
input Showcall10 = no;
input Showcall11 = no;
input Showcall12 = no;
input Showcall13 = no;
input Showcall14 = no;
input Showcall15 = no;
input Showcall16 = no;
input Showcall17 = no;
input Showcall18 = no;
input Showcall19 = no;
input Showcall20 = no;




### Put Option Volume
def putOptionVolume = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0));
def putOptionVolume1 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1));
def putOptionVolume2 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2));
def putOptionVolume3 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3));
def putOptionVolume4 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4));
def putOptionVolume5 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5));
def putOptionVolume6 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6));
def putOptionVolume7 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7));
def putOptionVolume8 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8));
def putOptionVolume9 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9));
def putOptionVolume10 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10));
def putOptionVolume11 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11));
def putOptionVolume13 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12));
def putOptionVolume12 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13));
def putOptionVolume14 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14));
def putOptionVolume15 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15));
def putOptionVolume16 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16));
def putOptionVolume17 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17));
def putOptionVolume18 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18));
def putOptionVolume19 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19));
def putOptionVolume20 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20));

###Call Option Volume
def callOptionVolume = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0));
def callOptionVolume1 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1));
def callOptionVolume2 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2));
def callOptionVolume3 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3));
def callOptionVolume4 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4));
def callOptionVolume5 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5));
def callOptionVolume6 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6));
def callOptionVolume7 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7));
def callOptionVolume8 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8));
def callOptionVolume9 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9));
def callOptionVolume10 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10));
def callOptionVolume11 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11));
def callOptionVolume12 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12));
def callOptionVolume13 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13));
def callOptionVolume14 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14));
def callOptionVolume15 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15));
def callOptionVolume16 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16));
def callOptionVolume17 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17));
def callOptionVolume18 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18));
def callOptionVolume19 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19));
def callOptionVolume20 = if IsNaN(volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20))) then 0 else volume("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20));


### Put Option ohlc4
def putOptionohlc4 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0));
def putOptionohlc41 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1));
def putOptionohlc42 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2));
def putOptionohlc43 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3));
def putOptionohlc44 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4));
def putOptionohlc45 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5));
def putOptionohlc46 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6));
def putOptionohlc47 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7));
def putOptionohlc48 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8));
def putOptionohlc49 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9));
def putOptionohlc410 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10));
def putOptionohlc411 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11));
def putOptionohlc412 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12));
def putOptionohlc413 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13));
def putOptionohlc414 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14));
def putOptionohlc415 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15));
def putOptionohlc416 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16));
def putOptionohlc417 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17));
def putOptionohlc418 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18));
def putOptionohlc419 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19));
def putOptionohlc420 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20));


####Call Option ohlc4
def callOptionohlc4 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0));
def callOptionohlc41 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1));
def callOptionohlc42 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2));
def callOptionohlc43 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3));
def callOptionohlc44 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4));
def callOptionohlc45 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5));
def callOptionohlc46 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6));
def callOptionohlc47 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7));
def callOptionohlc48 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8));
def callOptionohlc49 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9));
def callOptionohlc410 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10));
def callOptionohlc411 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11));
def callOptionohlc412 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12));
def callOptionohlc413 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13));
def callOptionohlc414 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14));
def callOptionohlc415 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15));
def callOptionohlc416 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16));
def callOptionohlc417 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17));
def callOptionohlc418 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18));
def callOptionohlc419 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19));
def callOptionohlc420 = if IsNaN(ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20))) then 0 else ohlc4("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20));


### Put Option tick_count
def putOptiontick_count = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 0));
def putOptiontick_count1 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 1));
def putOptiontick_count2 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 2));
def putOptiontick_count3 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 3));
def putOptiontick_count4 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 4));
def putOptiontick_count5 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 5));
def putOptiontick_count6 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 6));
def putOptiontick_count7 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 7));
def putOptiontick_count8 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 8));
def putOptiontick_count9 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 9));
def putOptiontick_count10 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 10));
def putOptiontick_count11 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 11));
def putOptiontick_count13 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 12));
def putOptiontick_count12 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 13));
def putOptiontick_count14 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 14));
def putOptiontick_count15 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 15));
def putOptiontick_count16 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 16));
def putOptiontick_count17 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 17));
def putOptiontick_count18 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 18));
def putOptiontick_count19 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 19));
def putOptiontick_count20 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "P" + AsPrice(PutStrike - strikeSpacing * 20));

####Call Option tick_count
def callOptiontick_count = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 0));
def callOptiontick_count1 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 1));
def callOptiontick_count2 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 2));
def callOptiontick_count3 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 3));
def callOptiontick_count4 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 4));
def callOptiontick_count5 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 5));
def callOptiontick_count6 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 6));
def callOptiontick_count7 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 7));
def callOptiontick_count8 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 8));
def callOptiontick_count9 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 9));
def callOptiontick_count10 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 10));
def callOptiontick_count11 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 11));
def callOptiontick_count12 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 12));
def callOptiontick_count13 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 13));
def callOptiontick_count14 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 14));
def callOptiontick_count15 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 15));
def callOptiontick_count16 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 16));
def callOptiontick_count17 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 17));
def callOptiontick_count18 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 18));
def callOptiontick_count19 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 19));
def callOptiontick_count20 = if IsNaN(tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20))) then 0 else tick_count("." + GetSymbol() + optionSeriesPrefix + "C" + AsPrice(CallStrike + strikeSpacing * 20));

####Show Individual Put Volume Labels
AddLabel(Showput or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 0) + ": " + putOptionVolume);
AddLabel(Showput1 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 1) + ": " + putOptionVolume1);
AddLabel(Showput2 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 2) + ": " + putOptionVolume2);
AddLabel(Showput3 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 3) + ": " + putOptionVolume3);
AddLabel(Showput4 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 4) + ": " + putOptionVolume4);
AddLabel(Showput5 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 5) + ": " + putOptionVolume5);
AddLabel(Showput6 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 6) + ": " + putOptionVolume6);
AddLabel(Showput7 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 7) + ": " + putOptionVolume7);
AddLabel(Showput8 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 8) + ": " + putOptionVolume8);
AddLabel(Showput9 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 9) + ": " + putOptionVolume9);
AddLabel(Showput10 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 10) + ": " + putOptionVolume10);
AddLabel(Showput11 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 11) + ": " + putOptionVolume11);
AddLabel(Showput12 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 12) + ": " + putOptionVolume12);
AddLabel(Showput13 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 13) + ": " + putOptionVolume13);
AddLabel(Showput14 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 14) + ": " + putOptionVolume14);
AddLabel(Showput15 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 15) + ": " + putOptionVolume15);
AddLabel(Showput16 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 16) + ": " + putOptionVolume16);
AddLabel(Showput17 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 17) + ": " + putOptionVolume17);
AddLabel(Showput18 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 18) + ": " + putOptionVolume18);
AddLabel(Showput19 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 19) + ": " + putOptionVolume19);
AddLabel(Showput20 or ShowAllLabels, "P" + AsPrice(PutStrike - strikeSpacing * 20) + ": " + putOptionVolume20);


#Show Individual Call Volume Labels
AddLabel(Showcall or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 0) + ": " + callOptionVolume, Color.CYAN);
AddLabel(Showcall1 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 1) + ": " + callOptionVolume1, Color.CYAN);
AddLabel(Showcall2 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 2) + ": " + callOptionVolume2, Color.CYAN);
AddLabel(Showcall3 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 3) + ": " + callOptionVolume3, Color.CYAN);
AddLabel(Showcall4 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 4) + ": " + callOptionVolume4, Color.CYAN);
AddLabel(Showcall5 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 5) + ": " + callOptionVolume5, Color.CYAN);
AddLabel(Showcall6 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 6) + ": " + callOptionVolume6, Color.CYAN);
AddLabel(Showcall7 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 7) + ": " + callOptionVolume7, Color.CYAN);
AddLabel(Showcall8 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 8) + ": " + callOptionVolume8, Color.CYAN);
AddLabel(Showcall9 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 9) + ": " + callOptionVolume9, Color.CYAN);
AddLabel(Showcall10 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 10) + ": " + callOptionVolume10, Color.CYAN);
AddLabel(Showcall11 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 11) + ": " + callOptionVolume11, Color.CYAN);
AddLabel(Showcall12 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 12) + ": " + callOptionVolume12, Color.CYAN);
AddLabel(Showcall13 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 13) + ": " + callOptionVolume13, Color.CYAN);
AddLabel(Showcall14 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 14) + ": " + callOptionVolume14, Color.CYAN);
AddLabel(Showcall15 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 15) + ": " + callOptionVolume15, Color.CYAN);
AddLabel(Showcall16 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 16) + ": " + callOptionVolume16, Color.CYAN);
AddLabel(Showcall17 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 17) + ": " + callOptionVolume17, Color.CYAN);
AddLabel(Showcall18 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 18) + ": " + callOptionVolume18, Color.CYAN);
AddLabel(Showcall19 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 19) + ": " + callOptionVolume19, Color.CYAN);
AddLabel(Showcall20 or ShowAllLabels, "C" + AsPrice(CallStrike + strikeSpacing * 20) + ": " + callOptionVolume20, Color.CYAN);


plot Callvol = ((callOptionVolume * callOptionohlc4 * 100) + (callOptionVolume1 * callOptionohlc41 * 100) + (callOptionVolume2 * callOptionohlc42 * 100) + (callOptionVolume3 * callOptionohlc43 * 100) + (callOptionVolume4 * callOptionohlc44 * 100) + (callOptionVolume5 * callOptionohlc45 * 100) + (callOptionVolume6 * callOptionohlc46 * 100) + (callOptionVolume7 * callOptionohlc47 * 100) + (callOptionVolume8 * callOptionohlc48 * 100) + (callOptionVolume9 * callOptionohlc49 * 100) + (callOptionVolume10 * callOptionohlc410 * 100) + (callOptionVolume11 * callOptionohlc411 * 100) + (callOptionVolume12 * callOptionohlc412 * 100) + (callOptionVolume13 * callOptionohlc413 * 100) + (callOptionVolume14 * callOptionohlc414 * 100) + (callOptionVolume15 * callOptionohlc415 * 100) + (callOptionVolume16 * callOptionohlc416 * 100) + (callOptionVolume17 * callOptionohlc417 * 100) + (callOptionVolume18 * callOptionohlc418 * 100) + (callOptionVolume19 * callOptionohlc419 * 100) + (callOptionVolume20 * callOptionohlc420 * 100)) / 1000;
plot Putvol = ((putOptionVolume * putOptionohlc4 * 100) + (putOptionVolume1 * putOptionohlc41 * 100) + (putOptionVolume2 * putOptionohlc42 * 100) + (putOptionVolume3 * putOptionohlc43 * 100) + (putOptionVolume4 * putOptionohlc44 * 100) + (putOptionVolume5 * putOptionohlc45 * 100) + (putOptionVolume6 * putOptionohlc46 * 100) + (putOptionVolume7 * putOptionohlc47 * 100) + (putOptionVolume8 * putOptionohlc48 * 100) + (putOptionVolume9 * putOptionohlc49 * 100) + (putOptionVolume10 * putOptionohlc410 * 100) + (putOptionVolume11 * putOptionohlc411 * 100) + (putOptionVolume12 * putOptionohlc412 * 100) + (putOptionVolume13 * putOptionohlc413 * 100) + (putOptionVolume14 * putOptionohlc414 * 100) + (putOptionVolume15 * putOptionohlc415 * 100) + (putOptionVolume16 * putOptionohlc416 * 100) + (putOptionVolume17 * putOptionohlc417 * 100) + (putOptionVolume18 * putOptionohlc418 * 100) + (putOptionVolume19 * putOptionohlc419 * 100) + (putOptionVolume20 * putOptionohlc420 * 100)) / 1000;

#NPTrading : Rounding to whole number
AddLabel(yes, "Callvol :" + AsPrice(Round(Callvol*1000,0)), Color.CYAN);
AddLabel(yes, "PutVol: " + AsPrice(Round(Putvol*1000, 0)), Color.LIGHT_RED);


plot Calltick = callOptiontick_count + callOptiontick_count1 + callOptiontick_count2 + callOptiontick_count3 + callOptiontick_count4 + callOptiontick_count5 + callOptiontick_count6 + callOptiontick_count7 + callOptiontick_count8 + callOptiontick_count9 + callOptiontick_count10 + callOptiontick_count11 + callOptiontick_count12 + callOptiontick_count13 + callOptiontick_count14 + callOptiontick_count15 + callOptiontick_count16 + callOptiontick_count17 + callOptiontick_count18 + callOptiontick_count19 + callOptiontick_count20;
plot Puttick = putOptiontick_count + putOptiontick_count1 + putOptiontick_count2 + putOptiontick_count3 + putOptiontick_count4 + putOptiontick_count5 + putOptiontick_count6 + putOptiontick_count7 + putOptiontick_count8 + putOptiontick_count9 + putOptiontick_count10 + putOptiontick_count11 + putOptiontick_count12 + putOptiontick_count13 + putOptiontick_count14 + putOptiontick_count15 + putOptiontick_count16 + putOptiontick_count17 + putOptiontick_count18 + putOptiontick_count19 + putOptiontick_count20;

AddLabel(yes, "CallTick :" + Calltick, Color.PLUM);
AddLabel(yes, "PutTick: " + Puttick, Color.YELLOW);


Putvol.SetPaintingStrategy(PaintingStrategy.LINE);
Callvol.SetPaintingStrategy(PaintingStrategy.LINE);
Putvol.SetDefaultColor(Color.LIGHT_RED);
Callvol.SetDefaultColor(Color.CYAN);

#Diff Cloud ?
AddCloud(Callvol, Putvol, Color.CYAN, Color.LIGHT_RED);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);

# individual Cloud ?
AddCloud(Callvol, ZeroLine, Color.CYAN, Color.LIGHT_RED);
AddCloud(Putvol, ZeroLine, Color.LIGHT_RED, Color.CYAN);

#NPTrading : Using PaintingStrategy.LINE_VS_SQUARES for visiblitity
Puttick.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
Calltick.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
Puttick.SetDefaultColor(Color.YELLOW);
Calltick.SetDefaultColor(Color.PLUM);

#NPTrading : ??
#AddCloud(Calltick, Puttick, Color.plum, Color.light_RED);

#NPTrading : ??
#AddCloud(Calltick, ZeroLine, Color.CYAN, Color.RED);
#AddCloud(Puttick, ZeroLine, Color.RED, Color.CYAN);

###################################
#StudyName: Dilbert_BlockTrade_V1
#Description: Identify bars with high volume relative to the tick_count. Such bars could indicate a block trade, or a possible change in trend.
#Author: Dilbert
#Requested By:
# Ver Date Auth Change
# V1 090717 Dilbert 1st code cut
# TOS.mx Link:
# Trading Notes: Identify bars with high volume relative to the tick_count. Such bars could indicate a block trade, or a possible change in trend.

#PUT RATIO
input AvgType = AverageType.EXPONENTIAL;
input MaLength = 20;
def V = Putvol;
def TC = Puttick;
def TradeSize = V / TC;

input displace = 0;
input SdLength = 20;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;

def sDev = StDev(data = TradeSize[-displace], length = SdLength);

def MA = MovingAverage(AvgType, TradeSize, MaLength);
plot Dot = if TradeSize > Ma + (sDev * Num_Dev_up) then Putvol else Double.NaN;
Dot.SetPaintingStrategy(PaintingStrategy.Points);
Dot.SetLineWeight(5);
Dot.AssignValueColor(color.red);

#CALL RATIO
input AvgType1 = AverageType.EXPONENTIAL;
input MaLength1 = 20;
def V1 = Callvol;
def TC1 = Calltick;
def TradeSize1 = V1 / TC1;

input displace1 = 0;
input SdLength1 = 20;
input Num_Dev_up1 = 2.0;
input averageType1 = AverageType.SIMPLE;

def sDev1 = StDev(data = TradeSize1[-displace1], length = SdLength1);

def MA1 = MovingAverage(AvgType1, TradeSize1, MaLength1);
plot Dot1 = if TradeSize1 > Ma1 + (sDev1 * Num_Dev_up1) then Callvol else Double.NaN;
Dot1.AssignValueColor(color.cyan);
Dot1.SetPaintingStrategy(PaintingStrategy.Points);
Dot1.SetLineWeight(5);
this works very well! Thank you BUT it doesnt show SPX options volume sadly :/ any idea why?
 
Code:
# Show SELL and BUY Volume and percentage.
# Referencing credit to Horserider script at https://usethinkscript.com/threads/volume-buy-sell-indicator-with-hot-percent-for-thinkorswim.389/
# Nomak 02/21/2020

declare upper;
input timeframe = AggregationPeriod.DAY;


def Vol = volume(period = timeframe);
def at_High = high(period = timeframe);
def at_Open = open(period = timeframe);
def at_Close = close(period = timeframe);
def at_Low = low(period = timeframe);
def Vol1 = volume(period = timeframe);
def at_High1 = high(period = timeframe);
def at_Open1 = open(period = timeframe);
def at_Close1 = close(period = timeframe);
def at_Low1 = low(period = timeframe);

# Buy_Volume forumla is volume * (close_price minus low_price) / (High_price minus low_price)
def Buy_Volume = roundup(Vol * (at_close - at_low) / (at_High - at_Low));
def Buy_percent = roundup((Buy_volume / Vol) * 100);

#Sell_Volume forumla is  volume * (High_price minus Close_price) / (High_price minus Low_price)
def Sell_Volume = rounddown(Vol1 * (at_High1 - at_Close1) / (at_High1 - at_low1));
def Sell_percent = roundup((Sell_Volume / Vol1) * 100);

Addlabel(yes, "BuyVol " + Buy_Volume, Color.Green);
Addlabel(yes, "SellVol " + Sell_Volume, Color.Red);
AddLabel(yes, "Buy % " + Buy_percent, Color.Green);
Addlabel(yes, "Sell % " + Sell_percent, Color.Red);
this works very well! Thank you BUT it doesnt show SPX options volume sadly :/ any idea why?
Sorry, I'm not sure. I use this script for volume buy-sell these days
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
652 Online
Create Post

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