String to Number

stellar0645

New member
Hello All,

I need to input a strike price and use it both as a number and as text. Only some guidance from TOS and the forum. It seems that TOS has limited text manipulation tools.

So, I can work with the Strike price as text but need to convert it into a number for subsequent math. And then back to text with no decimals.

Can this be done? Thanks very much . . . .

No responses, perhaps my request was confusing. Basically:
  • in TOS, convert numeric input variables from text to a number for manipulation
  • convert the resulting number back to text (with no decimals)
  • I have tried Concat, Round, RoundUp, Floor, Astext, etc., no luck
Thanks again . . . . .
 
Last edited:
Solution
I could write a long explanation if you wish, but its just easier to say that thinkscript hates strings. Always input as double if you need to perform anything dynamic like math. From there, Concat(Any,"") will convert to string. The string conversion should only appear in the final product, so to speak, and within in-line code.
Hello All,

I need to input a strike price and use it both as a number and as text. Only some guidance from TOS and the forum. It seems that TOS has limited text manipulation tools.

So, I can work with the Strike price as text but need to convert it into a number for subsequent math. And then back to text with no decimals.

Can this be done? Thanks very much . . . .

No responses, perhaps my request was confusing. Basically:
  • in TOS, convert numeric input variables from text to a number for manipulation
  • convert the resulting number back to text (with no decimals)
  • I have tried Concat, Round, RoundUp, Floor, Astext, etc., no luck
Thanks again . . . . .

i will guess , no, on the conversion. might be able to do something with some switch-case functions...?

sometimes people get stuck on trying to make a certain process fit a problem.
instead of asking several questions on some vague process, just ask the real question, what tasks are you trying to do?
 

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

i will guess , no, on the conversion. might be able to do something with some switch-case functions...?

sometimes people get stuck on trying to make a certain process fit a problem.
instead of asking several questions on some vague process, just ask the real question, what tasks are you trying to do?
Thanks, good thought.

I'm trying to plot option volumes:

This works:
AddLabel(yes, Symbol_start + Year + Month + Day + Type + Strike1, globalColor("Global2")); -> .SPXW220711C3870

This fails:

plot Vol1 = volume(Symbol_start + Year + Month + Day + Type + Strike1); -> .SPXW220711C3870
plot Vol2 = volume(Symbol_start + Year + Month + Day + Type + Strike2); -> .SPXW220711C3875

Inputting Strike1 as a text item works but I need it as a number so I can increment it 6 times then use it as text in 6 volume statements.

Thanks for any thoughts . . . . .
 
I could write a long explanation if you wish, but its just easier to say that thinkscript hates strings. Always input as double if you need to perform anything dynamic like math. From there, Concat(Any,"") will convert to string. The string conversion should only appear in the final product, so to speak, and within in-line code.
 
Solution
I could write a long explanation if you wish, but its just easier to say that thinkscript hates strings. Always input as double if you need to perform anything dynamic like math. From there, Concat(Any,"") will convert to string. The string conversion should only appear in the final product, so to speak, and within in-line code.
Thanks for that but, from my initial post
  • I have tried Concat, Round, RoundUp, Floor, Astext, etc., no luck
Concat works with Addlabel but not in the statement that calls the Volume request to the option itself.

I can provide the actual code later but that is the story.

Thanks . . . . .
 
Code:
declare lower;
input Strike = 3870;
def Hundreds = Strike % 1000;
def Thousands = (Strike - Hundreds) / 1000;
plot vol = volume(".SPXW220711C" + Concat(Thousands,"") + Concat(Hundreds,""));

ddtgfki.png


It does wonky things with the comma when the underlying is over 999
 
Okay, thanks very much. That looks very similar to something I already tried but I will code it up and see what happens.
Yes, the comma is a problem but I developed a workaround.
Thanks again..
 
Hello Joshua,

Yes, that did the trick. There must've been something not quite right with my earlier implementation of Concat.

I added some other inputs and created a series of six plots for each of the calls and puts plus labeling, etc. it works quite well.

Thanks again for that conversion tip . . . .
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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