Implied Volatility (IV) Rank & Percentile for ThinkorSwim

I've come this far getting my IV Percentile Script made for my watchlist. But I think something is missing. I can't tell if it's accurate for one, since I pulled this out of someone elses script. And then I also am getting a NaN result on about every 5 stocks out of 100 on my watchlist. Hoping someone knows what is wrong.

Thank you in advance!

Code:
input days_back = 252;

# implied volatility
# using proxies for futures

def df = if (GetSymbol() == "/ES") then close("VIX") / 100 else if (GetSymbol() == "/CL") then close("OIV") / 100  else if (GetSymbol() == "/GC") then close("GVX") / 100  else if (GetSymbol() == "/SI") then close("VXSLV") / 100  else if (GetSymbol() == "/NQ") then close("VXN") / 100  else if (GetSymbol() == "/TF") then close("RVX") / 100  else if (GetSymbol() == "/YM") then close("VXD") / 100  else if (GetSymbol() == "/6E") then close("EVZ") / 100  else if (GetSymbol() == "/ZN") then close("VXTYN") / 100  else imp_volatility();
def df1 = if !IsNaN(df) then df else df[-1];
# calculate the IV percentile
# how many times over the past year, has IV been below the current IV
def counts_below = fold i = 1 to days_back + 1 with count = 0  do    if df1[0] > df1[i] then count + 1   else count;
def iv_percentile = Round(counts_below / days_back * 100.0, 0);
plot IVPercentile = iv_percentile;


vh3ut3e.png



biSIlkv.png
 

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

I've come this far getting my IV Percentile Script made for my watchlist. But I think something is missing. I can't tell if it's accurate for one, since I pulled this out of someone elses script. And then I also am getting a NaN result on about every 5 stocks out of 100 on my watchlist. Hoping someone knows what is wrong.

Thank you in advance!

Code:
input days_back = 252;

# implied volatility
# using proxies for futures

def df = if (GetSymbol() == "/ES") then close("VIX") / 100 else if (GetSymbol() == "/CL") then close("OIV") / 100  else if (GetSymbol() == "/GC") then close("GVX") / 100  else if (GetSymbol() == "/SI") then close("VXSLV") / 100  else if (GetSymbol() == "/NQ") then close("VXN") / 100  else if (GetSymbol() == "/TF") then close("RVX") / 100  else if (GetSymbol() == "/YM") then close("VXD") / 100  else if (GetSymbol() == "/6E") then close("EVZ") / 100  else if (GetSymbol() == "/ZN") then close("VXTYN") / 100  else imp_volatility();
def df1 = if !IsNaN(df) then df else df[-1];
# calculate the IV percentile
# how many times over the past year, has IV been below the current IV
def counts_below = fold i = 1 to days_back + 1 with count = 0  do    if df1[0] > df1[i] then count + 1   else count;
def iv_percentile = Round(counts_below / days_back * 100.0, 0);
plot IVPercentile = iv_percentile;

why do you have -1 for an offset?
def df1 = if !IsNaN(df) then df else df[-1];

if there is an error, i think it should read the previous value, not the future value.
might need to add a check if bar#1.
def df1 = if barnumber() == 1 then 0 else if !IsNaN(df) then df else df[1];


when using fold, use getvalue, to read other values

def counts_below =
fold i = 1 to days_back + 1
with count = 0
do if df1[0] > getvalue(df1, i) then count + 1
else count;
 
Last edited:
Is there a way to create a custom quote column in a watchlist for IV Rank?
IV Rank watchlist script
HA03zy3.png

Ruby:
# ------------------------START BELOW THIS LINE--------------------------
#
# tastytrade/dough Research Team
# Michael Rechenthin, Ph.D.
# Follow me on twitter:  @mrechenthin
#
# IV Rank is a description of where the current IV lies in comparison
# to its yearly high and low IV
#
# IV Percentile gives the percentage of days over the last year, that
# were below the current IV.  If the IV Rank is above 50%, then
# the script will highlight it green; otherwise red.
#
# For information on the two, see Skinny on Options Data Science,
# titled "IV Rank and IV Percentile (w/ thinkscript)" on Nov 12, 2015
# http://ontt.tv/1Nt4fcS
#
# version 3.2
#
declare hide_on_intraday; # do not display when using intra-day plots
input days_back = 252; # it is most common to use 1-year (or 252 trading days)


def x;
if GetAggregationPeriod() > AggregationPeriod.DAY {
x=1;
} else {
x=2;
}

# implied volatility
# using proxies for futures

def df = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
else if (GetSymbol() == "/YM") then close("VXD") / 100
else if (GetSymbol() == "/6E") then close("EVZ") / 100
else if (GetSymbol() == "/6J") then close("JYVIX") / 100
else if (GetSymbol() == "/6B") then close("BPVIX") / 100
else if (GetSymbol() == "/ZN") then close("TYVIX") / 100
else if (Getsymbol() == "/ZW") then close("WIV") / 100
else if (Getsymbol() == "/ZB") then imp_volatility("TLT")
else if (Getsymbol() == "/ZC") then imp_volatility("CORN")
else if (Getsymbol() == "/ZS") then imp_volatility("SOYB")
else if (Getsymbol() == "/KC") then imp_volatility("JO")
else if (Getsymbol() == "/NG") then imp_volatility("UNG")
else if (Getsymbol() == "/6S") then imp_volatility("FXF")
else imp_volatility();


def df1 = if !IsNaN(df) then df else df[-1];


# calculate the IV rank
def low_over_timespan = Lowest(df1, days_back);
def high_over_timespan = Highest(df1, days_back);
def iv_rankCALC = Round( (df1 - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);
plot iv_rank = if !isNan(iv_rankCALC) then iv_rankCALC else 0;
AddLabel(yes, iv_rank, if iv_rank < 50 then Color.RED else
if iv_rank > 50 then Color.GREEN else  color.light_gray);

#AssignBackgroundColor(
#if iv_rank < 50 then Color.RED else
#if iv_rank > 50 then Color.GREEN else  color.light_gray);
 
Newbie here. Thanks for the script.

I'm not sure if this thread is the latest IVR info, but maybe this will help someone using futures.

I'm working with /GC and noticed that the implied volatility (as plotted by the ImpVolatility study) was identical to the IV Rank value and plot in this script.

Issue 1:
  • GetSymbol("/GC") returns "/GC:XCEC"
    • Note: entering /GC in the chart defaults to current month = June 2023, but GetSymbol() still returns "/GC:XCEC"
  • GetSymbol("/GCM23") returns "/GCM23:/XCEC"
    • Note: entering "/GCM23" in the chart explicitly specifies June 2023
Therefore, if I am trying to use "/GC" or "/GCM23", the code block falls through and ends up using imp_volatility()

Issue 2:

I modified the code to search for "/GC" and "/GCM23" which successfully matches and uses "GVX".

However, it looks like GVX is no longer the Gold Volatility Index - instead the Gold Volatility Index is "GVZ" per (CBOE). I'm not sure about the other futures.

I'm new to thinkscript (not to coding), I couldn't find a way to parse GetSymbol(), therefore the script will need to be updated each time the current futures month changes (please let me know if I'm wrong or there is a workaround)

Here are the changes for June Gold 2023. Note that something similar would need to be done for the other futures used (in the code or not in the code), or the script will use the out of the box ImpVolatility study.

Original Snippet:

Code:
def df = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
...
else imp_volatility();

Modified Snippet:
Code:
def df = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/GC:XCEC") then close("GVZ") / 100
else if (GetSymbol() == "/GCM23:XCEC") then close("GVZ") / 100
...
else imp_volatility();

Hope this helps someone.
 
Just a note: I used the code as in #1 and it looks fine in the Watchlist.

The output is the same as the "Tasty IV Percentile". When I get NaN (happens rarely) the Tasty plot fails too.
So it seems it works perfectly fine.

Additionally I took the default TOS IV_Percentlile script:

Code:
def vol = impVolatility();
rec data = if !isNaN(vol) then vol else data[1];
def hi = highest(data,252);
def lo = lowest(data,252);
plot perct = (data - lo)*100 / (hi - lo);

..and put it into Custom 1 and renamed it IV_Rank2 to avoid confusion.

PS: I love the Tasty CheatSheet - but not so much the quality. Here the same in a cleaner PDF: (I have it also in ODG)
 

Attachments

  • tasty.pdf
    42.6 KB · Views: 790
Last edited:
in the Scan->Stock Hacker
i added a custom filter of TastyTradeIVR > 50
but i am still getting stocks with low IVR
what i should put in the filter to get IVR>50 ?

any ideas ?

thanks
 
Last edited by a moderator:
in the Scan->Stock Hacker
i added a custom filter of TastyTradeIVR > 50
but i am still getting stocks with low IVR
what i should put in the filter to get IVR>50 ?

any ideas ?

thanks
Moved your question to this thread which should further your coding journey.
 
IV Rank watchlist script
View attachment 16213
Ruby:
# ------------------------START BELOW THIS LINE--------------------------
#
# tastytrade/dough Research Team
# Michael Rechenthin, Ph.D.
# Follow me on twitter:  @mrechenthin
#
# IV Rank is a description of where the current IV lies in comparison
# to its yearly high and low IV
#
# IV Percentile gives the percentage of days over the last year, that
# were below the current IV.  If the IV Rank is above 50%, then
# the script will highlight it green; otherwise red.
#
# For information on the two, see Skinny on Options Data Science,
# titled "IV Rank and IV Percentile (w/ thinkscript)" on Nov 12, 2015
# http://ontt.tv/1Nt4fcS
#
# version 3.2
#
declare hide_on_intraday; # do not display when using intra-day plots
input days_back = 252; # it is most common to use 1-year (or 252 trading days)


def x;
if GetAggregationPeriod() > AggregationPeriod.DAY {
x=1;
} else {
x=2;
}

# implied volatility
# using proxies for futures

def df = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
else if (GetSymbol() == "/YM") then close("VXD") / 100
else if (GetSymbol() == "/6E") then close("EVZ") / 100
else if (GetSymbol() == "/6J") then close("JYVIX") / 100
else if (GetSymbol() == "/6B") then close("BPVIX") / 100
else if (GetSymbol() == "/ZN") then close("TYVIX") / 100
else if (Getsymbol() == "/ZW") then close("WIV") / 100
else if (Getsymbol() == "/ZB") then imp_volatility("TLT")
else if (Getsymbol() == "/ZC") then imp_volatility("CORN")
else if (Getsymbol() == "/ZS") then imp_volatility("SOYB")
else if (Getsymbol() == "/KC") then imp_volatility("JO")
else if (Getsymbol() == "/NG") then imp_volatility("UNG")
else if (Getsymbol() == "/6S") then imp_volatility("FXF")
else imp_volatility();


def df1 = if !IsNaN(df) then df else df[-1];


# calculate the IV rank
def low_over_timespan = Lowest(df1, days_back);
def high_over_timespan = Highest(df1, days_back);
def iv_rankCALC = Round( (df1 - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);
plot iv_rank = if !isNan(iv_rankCALC) then iv_rankCALC else 0;
AddLabel(yes, iv_rank, if iv_rank < 50 then Color.RED else
if iv_rank > 50 then Color.GREEN else  color.light_gray);

#AssignBackgroundColor(
#if iv_rank < 50 then Color.RED else
#if iv_rank > 50 then Color.GREEN else  color.light_gray);
Merry, Thanks for your awesome work. Do you happen to have or perhaps adjust this IVRank column so that I can see the real-time change in IV for SPX/SPY/QQQ options within the past 5 minutes? I'd like to add a column to my 0-3dte WL that can highlight %changes to IV real-time. Thanks!
 
As new member to this forum. Thought I share this IV rank indicator for ThinkorSwim that helps me increase probability of success. This script was taken from tastytrade. The rule is to sell premiums that are at least above 50% IV rank. You can watch this video to find out more https://uat.tastytrade.com/tt/shows...nk-and-iv-percentile-w-thinkscript-11-12-2015

View attachment 5467

Code:
# ------------------------START BELOW THIS LINE--------------------------

#

# tastytrade/dough Research Team

# Michael Rechenthin, Ph.D.

# Follow me on twitter:  @mrechenthin

#

# IV Rank is a description of where the current IV lies in comparison

# to its yearly high and low IV

#

# IV Percentile gives the percentage of days over the last year, that

# were below the current IV.  If the IV Rank is above 50%, then

# the script will highlight it green; otherwise red.

#

# For information on the two, see Skinny on Options Data Science,

# titled "IV Rank and IV Percentile (w/ thinkscript)" on Nov 12, 2015

# http://ontt.tv/1Nt4fcS

#

# version 3.2

#

declare lower;

declare hide_on_intraday; # do not display when using intra-day plots

input days_back = 252; # it is most common to use 1-year (or 252 trading days)



def x;

if GetAggregationPeriod() > AggregationPeriod.DAY {

x=1;

} else {

x=2;

}

AddLabel(yes, if (x==1) then "This script should be used on daily charts only" else "");





# implied volatility

# using proxies for futures

def df = if (GetSymbol() == "/ES") then close("VIX") / 100

else if (GetSymbol() == "/CL") then close("OIV") / 100

else if (GetSymbol() == "/GC") then close("GVX") / 100

else if (GetSymbol() == "/SI") then close("VXSLV") / 100

else if (GetSymbol() == "/NQ") then close("VXN") / 100

else if (GetSymbol() == "/TF") then close("RVX") / 100

else if (GetSymbol() == "/YM") then close("VXD") / 100

else if (GetSymbol() == "/6E") then close("EVZ") / 100

else if (GetSymbol() == "/6J") then close("JYVIX") / 100

else if (GetSymbol() == "/6B") then close("BPVIX") / 100

else if (GetSymbol() == "/ZN") then close("TYVIX") / 100

else if (Getsymbol() == "/ZW") then close("WIV") / 100

else if (Getsymbol() == "/ZB") then imp_volatility("TLT")

else if (Getsymbol() == "/ZC") then imp_volatility("CORN")

else if (Getsymbol() == "/ZS") then imp_volatility("SOYB")

else if (Getsymbol() == "/KC") then imp_volatility("JO")

else if (Getsymbol() == "/NG") then imp_volatility("UNG")

else if (Getsymbol() == "/6S") then imp_volatility("FXF")

else imp_volatility();



def df1 = if !IsNaN(df) then df else df[-1];



# display regular implied volatility

# ---------------------------

AddLabel(yes, "IV: " + Round(df1 * 100.0, 0), Color.ORANGE);



# calculate the IV rank

# ---------------------------

# calculate the IV rank

def low_over_timespan = Lowest(df1, days_back);

def high_over_timespan = Highest(df1, days_back);



def iv_rank = Round( (df1 - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);



AddLabel(yes, "IV Rank: " + iv_rank + "%", if iv_rank > 50 then Color.GREEN else Color.RED);



# calculate the IV percentile

# ---------------------------

# how many times over the past year, has IV been below the current IV

def counts_below = fold i = 1 to days_back + 1 with count = 0

do

  if df1[0] > df1 then

    count + 1

  else

    count;



def iv_percentile = Round(counts_below / days_back * 100.0, 0);

plot IVs = df1 * 100;

IVs.SetLineWeight(3);

IVs.AssignValueColor(if iv_rank > 50 then Color.GREEN else Color.RED);



AddLabel(yes, "IV Percentile: " + iv_percentile + "% of days were below the past year's IV", if iv_percentile > 50 then Color.GREEN else Color.RED);



# thanks to Kevin Osborn for the following line

AddLabel(yes, if (GetSymbol() == "/6S" or GetSymbol() == "/ZB" or GetSymbol() == "/ZC" or GetSymbol() == "/NG" or GetSymbol() == "/ZS" or GetSymbol() == "/KC") then "* ETF based" else "", Color.BLACK);



# ------------------------END ABOVE THIS LINE--------------------------

How to Scan for IV Rank in ThinkorSwim

This is an IV (Implied Volatility) rank scanner that you can use.

Code:
def IV = if isNaN(imp_Volatility())
         then IV[1]
         else imp_Volatility();
def IVrank = (fold i = 0 to 252
              with p
              do p + if IV > getValue(IV, i)
                     then 1
                     else 0) / 252;
plot cond = IVrank > .9;

Notes from Mobius:
There are some bugs and did not work for all stock symbols.
Here is the updated version:
Esmed9L.png

http://tos.mx/!d7dJDCDc

Code:
# ------------------------START BELOW THIS LINE--------------------------
#
# tastytrade/dough Research Team
# Michael Rechenthin, Ph.D.
# Follow me on twitter:  @mrechenthin
#
# IV Rank is a description of where the current IV lies in comparison
# to its yearly high and low IV
#
# IV Percentile gives the percentage of days over the last year, that
# were below the current IV.  If the IV Rank is above 50%, then
# the script will highlight it green; otherwise red.
#
# For information on the two, see Skinny on Options Data Science,
# titled "IV Rank and IV Percentile (w/ thinkscript)" on Nov 12, 2015
# http://ontt.tv/1Nt4fcS
#
# version 3.2.7
# updated by WhitePath from www.OptionMarketMentor.com (6/25/2024)
# - Fixed IV Percentile always 0 and calculate correct Percentile
# - Added Average IV range with different COLOR
# - Added optional plot for IV Rank and Percentile and IV Cloud
# - Added optional level line for IV at low and average
# - Commented out hide on intraday (should work for any period)
#   (does not work for new stocks with less than a year of data)
#

declare lower;
#declare hide_on_intraday; # do not display when using intra-day plots
input IV_Year_Trading_Days = 252; # it is most common to use 1-year (or 252 trading days)
input IV_HalfYear_Trading_Days = 126; # it is most common to use 2-quarter (or 120 trading days)
input IV_Quarter_Trading_Days = 63; # it is most common to use 1-quarter (or 60 trading days)
input IV_Month_Trading_Days = 21; # it is most common to use 1-month (or 20 trading days)
input IV_Threshold_Low = 30; # it is the low threshold on the chart
input IV_Threshold_High = 50; # it is the high threshold on the chart
input IV_Show_High_Area = no;
input IV_Show_All_Labels = yes;

# -----------------------------------
# Limit this to Daily Chart only (Disabled by WhitePath)
# -----------------------------------
#def intraDay;
#if GetAggregationPeriod() < AggregationPeriod.DAY {
#intraDay=1;
#} else {
#intraDay=2;
#}
#AddLabel(yes, "IV Rank for " + GetAggregationPeriod(), COLOR.GRAY);
#AddLabel(yes, if (intraDay==1) then "IV Rank Not available for " + GetAggregationPeriod() else "");

# -----------------------------------
# IV calculations
# -----------------------------------
DefineGlobalColor("IV-COLOR-LOW", COLOR.LIME);
DefineGlobalColor("IV-COLOR-AVG", COLOR.GRAY);
DefineGlobalColor("IV-COLOR-HIGH", COLOR.PINK);

# using proxies for futures
# -----------------------------------
def iv_data = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
else if (GetSymbol() == "/YM") then close("VXD") / 100
else if (GetSymbol() == "/6E") then close("EVZ") / 100
else if (GetSymbol() == "/6J") then close("JYVIX") / 100
else if (GetSymbol() == "/6B") then close("BPVIX") / 100
else if (GetSymbol() == "/ZN") then close("TYVIX") / 100
else if (Getsymbol() == "/ZW") then close("WIV") / 100
else if (Getsymbol() == "/ZB") then imp_volatility("TLT")
else if (Getsymbol() == "/ZC") then imp_volatility("CORN")
else if (Getsymbol() == "/ZS") then imp_volatility("SOYB")
else if (Getsymbol() == "/KC") then imp_volatility("JO")
else if (Getsymbol() == "/NG") then imp_volatility("UNG")
else if (Getsymbol() == "/6S") then imp_volatility("FXF")
else imp_volatility();

# thanks to Kevin Osborn for the following line
# ----------------------------------
AddLabel(yes,
if (GetSymbol() == "/6S"
or GetSymbol() == "/ZB"
or GetSymbol() == "/ZC"
or GetSymbol() == "/NG"
or GetSymbol() == "/ZS"
or GetSymbol() == "/KC")
then "* ETF based"
else ""
, Color.YELLOW);

# display regular implied volatility
# ----------------------------------
#Plot IV
def ivs = Round(iv_data * 100, 2);

plot IV = ivs;
IV.SetLineWeight(1);
IV.SetStyle(Curve.POINTS);

#Plot IV High and Low Threshold
plot IVLow = IV_Threshold_Low;
IVLow.SetLineWeight(1);
IVLow.SetDefaultColor(color = Color.LIGHT_RED);
IVLow.Hide();

Plot IVHigh = IV_Threshold_High;
IVHigh.SetLineWeight(1);
IVHigh.SetDefaultColor(color = Color.LIGHT_GREEN);
IVHigh.Hide();

AddCloud(if IV_Show_High_Area then IVLow else double.nan, IVHigh, Color.GRAY, Color.Light_GREEN);

def low_over_timespan = LowestAll(ivs);
def high_over_timespan = HighestAll(ivs);
AddLabel(IV_Show_All_Labels, "IV MIN: " + Round(low_over_timespan,0) + "%", GlobalColor("IV-Color-LOW"));
#AddLabel(yes, "IV AVG(" + IV_Year_Range + "): " + round(Average(iv_data, IV_Year_Range) * 100,0) + "%", GlobalColor("IV-Color-AVG"));
#AddLabel(yes, "IV AVG(" + IV_2Quarter_Range + "): " + round(Average(iv_data, IV_2Quarter_Range) * 100,0) + "%", GlobalColor("IV-Color-AVG"));
#AddLabel(yes, "IV AVG(" + IV_Quarter_Range + "): " + round(Average(iv_data, IV_Quarter_Range) * 100,0) + "%", GlobalColor("IV-Color-AVG"));
#AddLabel(yes, "IV AVG(" + IV_Month_Range + "): " + round(Average(iv_data, IV_Month_Range) * 100,0) + "%", GlobalColor("IV-Color-AVG"));
AddLabel(IV_Show_All_Labels, "IV MAX: " + Round(high_over_timespan,0) + "%", GlobalColor("IV-Color-HIGH"));

AddLabel(yes, "IV: " + Round(ivs,0) + "%", if ivs > IV_Threshold_High then GlobalColor("IV-Color-HIGH") else (if ivs < IV_Threshold_Low then GlobalColor("IV-Color-LOW") else (if IsNaN(ivs) then Color.GRAY else GlobalColor("IV-Color-AVG"))));

# -----------------------------------
# IV Rank
# -----------------------------------
def ivr = Round( (ivs - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);

IV.AssignValueColor(if ivr > IV_Threshold_HIGH then GlobalColor("IV-Color-HIGH") else (if ivr <= IV_Threshold_LOW then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

AddLabel(yes, "IVR: " + ivr + "%",  if ivr > IV_Threshold_High then GlobalColor("IV-COLOR-HIGH") else (if ivr < IV_Threshold_Low then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

# -----------------------------------
# IV Percentile over different timeframes
# -----------------------------------
# how many times over the past year, has IV been below the current IV

def counts_below_y = fold py = 1 to IV_Year_Trading_Days + 1 with county = 0
do
  if !IsNaN(GetValue(ivs, py)) and GetValue(ivs, py) <= ivs then
    county + 1
  else
    county;

def ivp_year = if !isNaN(counts_below_y) then Round(counts_below_y / IV_Year_Trading_Days * 100.0, 0) else Double.NaN;
AddLabel(!isNaN(counts_below_y), "IVP: " + ivp_year + "%", if ivp_year > IV_Threshold_High then GlobalColor("IV-COLOR-HIGH") else (if ivp_year < IV_Threshold_Low then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

def counts_below_2q = fold p2q = 1 to IV_HalfYear_Trading_Days + 1 with count2q = 0
do
  if !IsNaN(GetValue(ivs, p2q)) and GetValue(ivs, p2q) <= ivs then
    count2q + 1
  else
    count2q;

def ivp_2q = if !isNaN(counts_below_2q) then Round(counts_below_2q / IV_HalfYear_Trading_Days * 100.0, 0) else Double.NaN;
AddLabel(!isNaN(counts_below_2q) and IV_Show_All_Labels, "IVP(6M): " + ivp_2q + "%", if ivp_2q > IV_Threshold_High then GlobalColor("IV-COLOR-HIGH") else (if ivp_2q < IV_Threshold_Low then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

def counts_below_q = fold pq = 1 to IV_Quarter_Trading_Days + 1 with countq = 0
do
  if !IsNaN(GetValue(ivs, pq)) and GetValue(ivs, pq) <= ivs then
    countq + 1
  else
    countq;

def ivp_q = if !isNaN(counts_below_q) then Round(counts_below_q / IV_Quarter_Trading_Days * 100.0, 0) else Double.NaN;
AddLabel(!isNaN(counts_below_q) and IV_Show_All_Labels, "IVP(3M): " + ivp_q + "%", if ivp_q > IV_Threshold_High then GlobalColor("IV-COLOR-HIGH") else (if ivp_q < IV_Threshold_Low then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

def counts_below_m = fold pm = 1 to IV_Month_Trading_Days + 1 with countm = 0
do
  if !IsNaN(GetValue(ivs, pm)) and GetValue(ivs, pm) <= ivs then
    countm + 1
  else
    countm;

def ivp_m = if !isNaN(counts_below_m) then Round(counts_below_m / IV_Month_Trading_Days * 100.0, 0) else Double.NaN;
AddLabel(!isNaN(counts_below_m) and IV_Show_All_Labels, "IVP(M): " + ivp_m + "%", if ivp_m > IV_Threshold_High then GlobalColor("IV-COLOR-HIGH") else (if ivp_m < IV_Threshold_Low then GlobalColor("IV-COLOR-LOW") else GlobalColor("IV-COLOR-AVG")));

# ------------------------END ABOVE THIS LINE--------------------------
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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