text progress bar , 0 to 100 for ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
text progress bar , 0 to 100

this displays a quantity of characters, in a label, 0 to 100, from a number.
i picked 0 to 100, with the intention of it displaying a number range as a percentage.
it uses combinations of 3 groups of characters , 1, 5, 25, to create the desired total.
i chose these because a small quantity of conditions are needed to display up to 100 chars.
.. 5 x 1s , 4 x 5s , 4 x 25s

there are labels that show the input number and the quantity of each group needed.
it will show the quantities for larger numbers, but only accurately display up to 124 chars.

Ruby:
# horz_progress_bar_01

# halcyonguy
# 22-04-04
# build a horizontal progress bar, 1 to 100
# from text chars
#  div  1, 5, 25

# this is actually narrower than the vertical line
input c1 = "]";
input c5 = "]]]]]";
input c25 = "]]]]]]]]]]]]]]]]]]]]]]]]]";

#input c1 = "|";
#input c5 = "|||||";
#input c25 = "|||||||||||||||||||||||||";

input test_num = 38;
def t = test_num;

script divqty {
input num = 0;
input div = 0;
plot quot = floor(num/div);
plot remain = num % div;
}

def div1 = 1;
def div5 = 5;
def div25 = 25;

# divide by biggest
def q25 = divqty(t, div25).quot;
def r25 = divqty(t, div25).remain;
# divide by smaller
def q5 = divqty(r25, div5).quot;
def r5 = divqty(r25, div5).remain;
# divide by smallest
def q1 = divqty(r5, div1).quot;
def r1 = divqty(r5, div1).remain;

addlabel(1 , "    " , color.black);
addlabel(1 , t , color.yellow);
addlabel(1 , "  " , color.black);
addlabel(1 , q25 + " * " + div25 + " = " + (q25 * div25), color.yellow);
addlabel(1 , q5 + " * " + div5 + " = " + (q5 * div5), color.yellow);
addlabel(1 , q1 + " * " + div1 + " = " + (q1 * div1), color.yellow);
addlabel(1 , "  " , color.black);

addlabel(1, 
(if q25 == 1 then c25 else if q25 == 2 then c25 + c25 else if q25 == 3 then c25 + c25 + c25 else if q25 == 4  then c25 + c25 + c25 + c25 else "") + 
(if q5 == 1 then c5 else if q5 == 2 then c5 + c5 else if q5 == 3 then c5 + c5 + c5 else if q5 == 4  then c5 + c5 + c5 + c5 else "") + 
(if q1 == 1 then c1 else if q1 == 2 then c1 + c1 else if q1 == 3 then c1 + c1 + c1 else if q1 == 4  then c1 + c1 + c1 + c1 else "")
, color.yellow);
#

GGzBmD4.jpg
 

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

text progress bar , 0 to 100

this displays a quantity of characters, in a label, 0 to 100, from a number.
i picked 0 to 100, with the intention of it displaying a number range as a percentage.
it uses combinations of 3 groups of characters , 1, 5, 25, to create the desired total.
i chose these because a small quantity of conditions are needed to display up to 100 chars.
.. 5 x 1s , 4 x 5s , 4 x 25s

there are labels that show the input number and the quantity of each group needed.
it will show the quantities for larger numbers, but only accurately display up to 124 chars.

Ruby:
# horz_progress_bar_01

# halcyonguy
# 22-04-04
# build a horizontal progress bar, 1 to 100
# from text chars
#  div  1, 5, 25

# this is actually narrower than the vertical line
input c1 = "]";
input c5 = "]]]]]";
input c25 = "]]]]]]]]]]]]]]]]]]]]]]]]]";

#input c1 = "|";
#input c5 = "|||||";
#input c25 = "|||||||||||||||||||||||||";

input test_num = 38;
def t = test_num;

script divqty {
input num = 0;
input div = 0;
plot quot = floor(num/div);
plot remain = num % div;
}

def div1 = 1;
def div5 = 5;
def div25 = 25;

# divide by biggest
def q25 = divqty(t, div25).quot;
def r25 = divqty(t, div25).remain;
# divide by smaller
def q5 = divqty(r25, div5).quot;
def r5 = divqty(r25, div5).remain;
# divide by smallest
def q1 = divqty(r5, div1).quot;
def r1 = divqty(r5, div1).remain;

addlabel(1 , "    " , color.black);
addlabel(1 , t , color.yellow);
addlabel(1 , "  " , color.black);
addlabel(1 , q25 + " * " + div25 + " = " + (q25 * div25), color.yellow);
addlabel(1 , q5 + " * " + div5 + " = " + (q5 * div5), color.yellow);
addlabel(1 , q1 + " * " + div1 + " = " + (q1 * div1), color.yellow);
addlabel(1 , "  " , color.black);

addlabel(1,
(if q25 == 1 then c25 else if q25 == 2 then c25 + c25 else if q25 == 3 then c25 + c25 + c25 else if q25 == 4  then c25 + c25 + c25 + c25 else "") +
(if q5 == 1 then c5 else if q5 == 2 then c5 + c5 else if q5 == 3 then c5 + c5 + c5 else if q5 == 4  then c5 + c5 + c5 + c5 else "") +
(if q1 == 1 then c1 else if q1 == 2 then c1 + c1 else if q1 == 3 then c1 + c1 + c1 else if q1 == 4  then c1 + c1 + c1 + c1 else "")
, color.yellow);
#  hal_prog


an updated progress bar
this has 2 colors, green for the data percent, purple for the remaining number


Code:
# horz_progress_bar_02d

# progress bar (labels)
# place this code at the end of a study and calculate a percent number for the data to display

#------------------------
# 23-10  chg to- 2 colors
# halcyonguy
# 22-04-04
# build a horizontal progress bar, 1 to 100
#------------------------
# enter a % number to display in a progress bar
input percent = 38;
#------------------------
def p = percent;
def q = 100 - p;

def div1 = 1;
def div5 = 5;
def div25 = 25;
#  ] is narrower than the vertical line
input c1 = "]";
input c5 = "]]]]]";
input c25 = "]]]]]]]]]]]]]]]]]]]]]]]]]";
#input c1 = " ";
#input c5 = "     ";
#input c25 = "                         ";
#input c1 = "|";
#input c5 = "|||||";
#input c25 = "|||||||||||||||||||||||||";

#----------------------------
# colors

DefineGlobalColor("elapsed_c", color.green);
DefineGlobalColor("remaining_c", color.magenta);
#GlobalColor("elapsed_c")
#GlobalColor("remaining_c")

#-----------------------
# elapsed data

# divide by biggest
def eq25 = floor(p/div25);
def er25 = p % div25;
# divide by smaller
def eq5 = floor(er25/div5);
def er5 = er25 % div5;
# divide by smallest
def eq1 = floor(er5/div1);
def er1 = er5 % div1;

addlabel(1, "  ", color.black);
addlabel(1, " ", color.cyan);
addlabel(1,
(if eq25 == 1 then c25 else if eq25 == 2 then c25 + c25 else if eq25 == 3 then c25 + c25 + c25 else if eq25 == 4  then c25 + c25 + c25 + c25 else "") +
(if eq5 == 1 then c5 else if eq5 == 2 then c5 + c5 else if eq5 == 3 then c5 + c5 + c5 else if eq5 == 4  then c5 + c5 + c5 + c5 else "") +
(if eq1 == 1 then c1 else if eq1 == 2 then c1 + c1 else if eq1 == 3 then c1 + c1 + c1 else if eq1 == 4  then c1 + c1 + c1 + c1 else "")
, GlobalColor("elapsed_c"));
#, color.yellow);

#-----------------------
# remaining data

# divide by biggest
def rq25 = floor(q/div25);
def rr25 = q % div25;
# divide by smaller
def rq5 = floor(rr25/div5);
def rr5 = rr25 % div5;
# divide by smallest
def rq1 = floor(rr5/div1);
def rr1 = rr5 % div1;

addlabel(1,
(if rq25 == 1 then c25 else if rq25 == 2 then c25 + c25 else if rq25 == 3 then c25 + c25 + c25 else if rq25 == 4  then c25 + c25 + c25 + c25 else "") +
(if rq5 == 1 then c5 else if rq5 == 2 then c5 + c5 else if rq5 == 3 then c5 + c5 + c5 else if rq5 == 4  then c5 + c5 + c5 + c5 else "") +
(if rq1 == 1 then c1 else if rq1 == 2 then c1 + c1 else if rq1 == 3 then c1 + c1 + c1 else if rq1 == 4  then c1 + c1 + c1 + c1 else "")
, GlobalColor("remaining_c"));
addlabel(1, " ", color.cyan);
addlabel(1, "  ", color.black);

#-----------------------
addlabel(1, floor(p) + "%", color.yellow);
#-----------------------

# test data

input test1_elapsed = no;
addlabel(test1_elapsed , "    " , color.black);
addlabel(test1_elapsed , p , color.yellow);
addlabel(test1_elapsed , "  " , color.black);
addlabel(test1_elapsed , eq25 + " * " + div25 + " = " + (eq25 * div25), color.yellow);
addlabel(test1_elapsed , eq5 + " * " + div5 + " = " + (eq5 * div5), color.yellow);
addlabel(test1_elapsed , eq1 + " * " + div1 + " = " + (eq1 * div1), color.yellow);
addlabel(test1_elapsed , "  " , color.black);

input test2_remaining = no;
addlabel(test2_remaining , "    " , color.black);
addlabel(test2_remaining , q , color.yellow);
addlabel(test2_remaining , "  " , color.black);
addlabel(test2_remaining , rq25 + " * " + div25 + " = " + (rq25 * div25), color.yellow);
addlabel(test2_remaining , rq5 + " * " + div5 + " = " + (rq5 * div5), color.yellow);
addlabel(test2_remaining , rq1 + " * " + div1 + " = " + (rq1 * div1), color.yellow);
addlabel(test2_remaining , "  " , color.black);
#

test numbers
green shows data number, purple is remaining
djuTFbR.jpg
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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