chasedeals
New member
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!
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;