Choose how many labels you want from a drop-down menu

Thinker20

New member
Good evening, hope you are doing great.
I have been writing a code that involves labels with the "AddLabel()" function but I want to know if it's possible to use the function switch and select from a drop-down menu if I want for example 2 labels to appear, is this possible? I haven't been able to do it since the switch statement needs to define or plot something before and that can't be done with this function.
I attached the code for a better understanding of what I want, any help in order to do this from a single menu (not selecting which one I want and which one doesn't individually), will be greatly appreciated, thank you very much in advance.
Code:
input MovingAverages = {default "1", "2", "3", "4", "5"};
input Price = close;
input ma1Length = 10;
input AverageTypeMa1 = AverageType.EXPONENTIAL;
input ma2Length = 20;
input AverageTypeMa2 = AverageType.EXPONENTIAL;
input ma3Length = 30;
input AverageTypeMa3 = AverageType.EXPONENTIAL;
input ma4Length = 40;
input AverageTypeMa4 = AverageType.EXPONENTIAL;
input ma5Length = 50;
input AverageTypeMa5 = AverageType.EXPONENTIAL;
input Value = 100;

def MA1 = MovingAverage(AverageTypeMa1, Price, ma1Length);
def MA2 = MovingAverage(AverageTypeMa2, Price, ma2Length);
def MA3 = MovingAverage(AverageTypeMa3, Price, ma3Length);
def MA4 = MovingAverage(AverageTypeMa4, Price, ma4Length);
def MA5 = MovingAverage(AverageTypeMa5, Price, ma5Length);

AddLabel(MovingAverages, MA1);

plot Label;
switch (MovingAverages){
case "1":
    Label = AddLabel(yes,MA1);
}
 
Good evening, hope you are doing great.
I have been writing a code that involves labels with the "AddLabel()" function but I want to know if it's possible to use the function switch and select from a drop-down menu if I want for example 2 labels to appear, is this possible? I haven't been able to do it since the switch statement needs to define or plot something before and that can't be done with this function.
I attached the code for a better understanding of what I want, any help in order to do this from a single menu (not selecting which one I want and which one doesn't individually), will be greatly appreciated, thank you very much in advance.
Code:
input MovingAverages = {default "1", "2", "3", "4", "5"};
input Price = close;
input ma1Length = 10;
input AverageTypeMa1 = AverageType.EXPONENTIAL;
input ma2Length = 20;
input AverageTypeMa2 = AverageType.EXPONENTIAL;
input ma3Length = 30;
input AverageTypeMa3 = AverageType.EXPONENTIAL;
input ma4Length = 40;
input AverageTypeMa4 = AverageType.EXPONENTIAL;
input ma5Length = 50;
input AverageTypeMa5 = AverageType.EXPONENTIAL;
input Value = 100;

def MA1 = MovingAverage(AverageTypeMa1, Price, ma1Length);
def MA2 = MovingAverage(AverageTypeMa2, Price, ma2Length);
def MA3 = MovingAverage(AverageTypeMa3, Price, ma3Length);
def MA4 = MovingAverage(AverageTypeMa4, Price, ma4Length);
def MA5 = MovingAverage(AverageTypeMa5, Price, ma5Length);

AddLabel(MovingAverages, MA1);

plot Label;
switch (MovingAverages){
case "1":
    Label = AddLabel(yes,MA1);
}
See if this helps you make what you want

Code:
input MovingAverages = 2;#Hint Movingaverages: Must be between 1 through 5
AddLabel(!Between(MovingAverages, 1, 5), "Movingaverages must be between 1 and 5", Color.YELLOW);

input Price = close;
input ma1Length = 10;
input AverageTypeMa1 = AverageType.EXPONENTIAL;
input ma2Length = 20;
input AverageTypeMa2 = AverageType.EXPONENTIAL;
input ma3Length = 30;
input AverageTypeMa3 = AverageType.EXPONENTIAL;
input ma4Length = 40;
input AverageTypeMa4 = AverageType.EXPONENTIAL;
input ma5Length = 50;
input AverageTypeMa5 = AverageType.EXPONENTIAL;
input Value = 100;

def MA1 = MovingAverage(AverageTypeMa1, Price, ma1Length);
def MA2 = MovingAverage(AverageTypeMa2, Price, ma2Length);
def MA3 = MovingAverage(AverageTypeMa3, Price, ma3Length);
def MA4 = MovingAverage(AverageTypeMa4, Price, ma4Length);
def MA5 = MovingAverage(AverageTypeMa5, Price, ma5Length);

AddLabel(Between(MovingAverages, 1, 5), ma1Length + ": " + AsText(MA1), Color.WHITE);
AddLabel(Between(MovingAverages, 2, 5), ma2Length + ": " + AsText(MA2), Color.WHITE);
AddLabel(Between(MovingAverages, 3, 5), ma3Length + ": " + AsText(MA3), Color.WHITE);
AddLabel(Between(MovingAverages, 4, 5), ma4Length + ": " + AsText(MA4), Color.WHITE);
AddLabel(Between(MovingAverages, 5, 5), ma5Length + ": " + AsText(MA5), Color.WHITE);
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
322 Online
Create Post

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