Watchlist all output as two digits

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);
 
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);

iv percent , add leading 0's
i added 1 and 2 zeros to the numbers , because there are values of 100 (3 digits)

a column expects just 1 output, plot or label, not both.
disable the plot formula and use label.

the color in a label will be the font color. so change it to black.

i added background color, but it wasn't working.
i realized using a -1 offset, causes data not to calculate on the last bar, which is what a column needs. so the numbers showing were from the 2nd to last bar. the last bar had NA.
i changed this from a negative offset to a positive
#def df1 = if !IsNaN(df) then df else df[-1];
def df1 = if !IsNaN(df) then df else df[1];

usually, getvalue() is used within a fold, instead of [ ] , but when i tried it, the background color went black. so there is an NA somewhere??

check what value is used for days_back. i might have had it set differently when i made the share?


column study
zivper
http://tos.mx/!BSzNNAGn


Code:
#zivper

#https://usethinkscript.com/threads/watchlist-all-output-as-two-digits.17217/
#Watchlist all output as two digits
#BiggySmall  12/4

#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.

input days_back = 252;
#input days_back = 50;

# 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];
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;
def 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);

AddLabel(1, 
(if IVP < 10 then "00" else if ivp < 100 then "0" else "") + ivp
#(if IVP < 10 then "0" else "") + ivp
, Color.black);

assignbackgroundcolor( 
 if IVP > 60 then Color.DARK_ORANGE
 else if IVP > 49 then Color.MAGENTA
 else color.gray);
#

KnyUXwr.jpg
 

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