Make a number to a string and format it so that each character is appended with a /n

Example:
Convert a Number to String:
123 to "1" + "/n" + "2" + "/n"+"3"+"/n"
Not exactly sure what you want, but here is an addchartbubble with the 123 converted to a stacked 123.

Ruby:
plot Data = expaverage(close,8) crosses close;
addchartBubble(data,high,"1\n2\n3", color = Color.WHITE);
Screenshot-2021-08-06-184320.png
 

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

Not exactly sure what you want, but here is an addchartbubble with the 123 converted to a stacked 123.
Here is another method that creates a label with the hopefully any 3 digit number you input.
Ruby:
input data = 592;
def digit1 = Round(Floor(data / 100), 0);
def digit2 = Floor((data - Round(Floor(data / 100), 0) * 100) / 10);
def digit3 = (data - Round(Floor(data / 100), 0) * 100) / 10 % 1 * 10;

addlabel(1,digit1+"/n"+digit2+"/n"+digit3+"/n",color.white);
 
Holy crap that is actually quite impressive. I guess I prematurely resigned myself to just accepting that ThinkScript has a total lack of support for strings and I never even bothered to attempt a mathematical approach like that.
 
Last edited:
Here is another method that creates a label with the hopefully any 3 digit number you input.
Works perfectly thanks. Is there a way to dynamically convert a double to a string and then process? For example if the close = 4268.32 then I need to know that it has 4 digits to process instead of 3. Also why is it I cannot assign string to AsText. Input string1 = AsText(....) doesn't work.
 
Works perfectly thanks. Is there a way to dynamically convert a double to a string and then process? For example if the close = 4268.32 then I need to know that it has 4 digits to process instead of 3. Also why is it I cannot assign string to AsText. Input string1 = AsText(....) doesn't work.
TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.

Ruby:
input x = 1;
AddLabel(1, if x == 1 then "Hello" else "Goodbye", Color.WHITE);
input c = 4268.32;
AddLabel(1, if Between(c / 1000, 1, 9) then "4 digits" else "Not 4 digits" , Color.WHITE);
 
TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.
Thanks a lot. Perfect example for me to extend and make it work.
 
TOS's string functionality is limited.

You cannot input string1 = AsText(...). Look up that function in the education tab for a further explanation of its use.

You can input text as part of a switch/case scenario, for example, input PivotType = {Woodies, Floor, default Camarilla};.

The following code has an example of how to use an input to create text in a label.

The other example helps to determine if the input 'c' value is exactly a 4 digit number.
thanks for sharing , sleepyz. i forget to use between.
here is a mod of post#6 , to allow the user to pick the quantity of digits

Ruby:
#
input quantity_of_digits = 4;
def powernum = (quantity_of_digits-1);
def c = close;
def p = power(10, powernum);
#addlabel(1, p, color.magenta);
#AddLabel(1, if Between(c / 1000, 1, 9) then "4 digits" else "Not 4 digits" , Color.WHITE);
AddLabel(1, if Between(c / p, 1, 9) then (quantity_of_digits + " digits") else ("Not " + quantity_of_digits + " digits") , Color.WHITE);
#


Ruby:
## determine quantity of digits in price
def digits = if Between(c / 1, 1, 9) then 1
else if Between(c / 10, 1, 9) then 2
else if Between(c / 100, 1, 9) then 3
else if Between(c / 1000, 1, 9) then 4
else if Between(c / 10000, 1, 9) then 5
else 0;
addlabel(1, "digits in price " + digits, color.yellow);
 
Last edited:
Hi, I am wondering if anyone could provide guidance on how to reference a section of values within a string value.
For example:
input numstring = 529755297652977529785297952980
def level_1 = first five characters in string (52975) (1st-5th character)
def level_2 = next five characters in string (52976) (6th-10th character)
def level_3 = next five characters in string (52977) 11th-15th character)
etc......

I can make this function work in excel using the =MID variable. I was just hoping there was a way to do this in Thinkscript as well.

Thanks
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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