Help with forming a string for AddLabel

raj2ras

New member
I am new to ThinkScript and trying to print a label for chart that says for e.g.

I want: $diff Close - EDMA21 = 4.50
I get: $diff 0-50 = 4.50

The challenge is, how do I create the string to display? Seems like I need some advanced conditional statements. If I try to concat the variables it just prints numbers?
:confused::unsure:


Code:
input price = close;
input Aggregation = AggregationPeriod.DAY;
input AvgType = AverageType.SIMPLE;
input Length = 50;

def diff = price - MovingAverage(AvgType, close(period = Aggregation), Length);
#def lname = concat(price, Aggregation + AvgType + Length );

#Labels
AddLabel(diff, Concat("$diff " ,AvgType + "-" + Length + " = " + Round(diff, 2)), CreateColor(107, 180, 4));

#AddLabel(diff, Concat("$diff " ,concat(price, Aggregation + AvgType + Length ) + " = " + Round(diff, 2)), CreateColor(107, 180, 4));
 
@raj2ras I'm not quite getting what your trying to explain... It sounds like you are confused because you haven't adequately research the AddLabel() function in the Thinkscript Learning Center... The examples there thoroughly explain how to concatenate strings with data... And if you need more examples, simply review the hundreds, if not thousands, of Thinkscripts here in these forums to see how others have accomplished this task...

In all sincerity, the use of the Concat() function is awkwardly redundant as you can accomplish more without it than with it... That may be the source of your confusion... Just use the + sign between strings and numbers and be sure to add " " between numbers and operators to negate math calculations where you don't want them...

One problem you will encounter it that AvgType will display then entire AverageType.Type unless you add another line of code... Again, you can learn a lot by checking how others do it... I'm not going to give you the entire answer because I can see that you are working at this and I'm sure you can find the correct solution with a bit of effort on your part... Keep at it and post again if you need more help... Learning works better when you do the work...

Keep at it...
 

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

I am new to ThinkScript and trying to print a label for chart that says for e.g.

I want: $diff Close - EDMA21 = 4.50
I get: $diff 0-50 = 4.50

The challenge is, how do I create the string to display? Seems like I need some advanced conditional statements. If I try to concat the variables it just prints numbers?
:confused::unsure:


Code:
input price = close;
input Aggregation = AggregationPeriod.DAY;
input AvgType = AverageType.SIMPLE;
input Length = 50;

def diff = price - MovingAverage(AvgType, close(period = Aggregation), Length);
#def lname = concat(price, Aggregation + AvgType + Length );

#Labels
AddLabel(diff, Concat("$diff " ,AvgType + "-" + Length + " = " + Round(diff, 2)), CreateColor(107, 180, 4));

#AddLabel(diff, Concat("$diff " ,concat(price, Aggregation + AvgType + Length ) + " = " + Round(diff, 2)), CreateColor(107, 180, 4));
to display the type of average, i would add an if then in the addlabel, to compare avgtype to the possible values, to pick a text value
if AvgType == AverageType.EXPONENTIAL then "EMA"
 
to display the type of average, i would add an if then in the addlabel, to compare avgtype to the possible values, to pick a text value
if AvgType == AverageType.EXPONENTIAL then "EMA"

Correct... You can either use a complex logic structure or simply use a separate line for each AverageType and AggregationPeriod so they display as strings...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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