BiggySmall
New member
I'm using this IV Percentile watchlist. Can somone add a leading zero to all single digits, so all output would be two digits? I want to sort it properly asending/decending. Thanks.
Code:
input days_back = 252;
# 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);
# Display actual IV Percentile
plot IVP = iv_percentile;
AddLabel(yes, IVP, if IVP > 49 and IVP < 60 then Color.MAGENTA else if IVP > 60 and IVP < 100 then Color.DARK_ORANGE else color.CURRENT);