Dynamic number of input variables?

BlueRaven

New member
I don't' know if it's possible with thinkscript or not... but I would like to have a dynamic amount of input variables....

A simple example would be one study with an adjustable amount of moving averages... It could either let me select how many I want displayed... or it would just add one more each time I filled one in...

So it would only display the input for length for however many MA's I wanted at a time. If I want one MA it only has one input for length... but if I want 10 MA's then it has 10 inputs for length...
 
I don't' know if it's possible with thinkscript or not... but I would like to have a dynamic amount of input variables....

A simple example would be one study with an adjustable amount of moving averages... It could either let me select how many I want displayed... or it would just add one more each time I filled one in...

So it would only display the input for length for however many MA's I wanted at a time. If I want one MA it only has one input for length... but if I want 10 MA's then it has 10 inputs for length...

TOS requires a plot for each moving average in your example and a separate input for length for each plot, making your idea near impossible. Nevertheless, here is one way to do something close to what you are requesting. You can choose however many predefined plots you want displayed. You could adjust the lengths and could have variables for price and average type for each ( in the code the later two are set to apply to all). In the code below the input display is set to 2 and the first 2 moving averages will plot but not the third one. You can add as many predefined plots as you want.

Ruby:
input display = 2;
input length1 = 8;
input length2 = 13;
input length3 = 21;
input price   = close;
input avgtype = averageType.EXPONENTIAL;
plot ma1 = if display < 1 then double.nan else movingAverage(avgtype, price, length1);
plot ma2 = if display < 2 then double.nan else movingAverage(avgtype, price, length2);
plot ma3 = if display < 3 then double.nan else movingAverage(avgtype, price, length3);
 

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

Hmmm... yeah I was afraid of this...

I'm really trying to limit the number of inputs shown on the options panel of the study to only what is needed at the time... I'm not doing MA's, it was just an easy example.
 
Hmmm... yeah I was afraid of this...

I'm really trying to limit the number of inputs shown on the options panel of the study to only what is needed at the time... I'm not doing MA's, it was just an easy example.

You can look up the 'script' and 'switch' functions to see if they miight work for your purposes. They are useful in limiting studies.
 
You can look up the 'script' and 'switch' functions to see if they miight work for your purposes. They are useful in limiting studies.
I'd never looked at the "script" function before... seems to just be a "function" function common in other languages... but it seems rather limited....

I've tried a couple things but haven't gotten anywhere with changing the number of inputs dynamically on the options panel...
 
Did you ever end up finding a suitable solution? I have a similar problem and have not had any luck with the "script" function. Is there any helpful guidance on the "script" function that anyone would suggest? Nothing I have found has worked.
 
Did you ever end up finding a suitable solution? I have a similar problem and have not had any luck with the "script" function. Is there any helpful guidance on the "script" function that anyone would suggest? Nothing I have found has worked.

what is it you are trying to do?
post the codes you have tried, in a code window.


you have to set up the max quantity of variables & plots that might be used. then compare a variable to determine if it is valid data. if not, don't plot it.

an example, this has 8 inputs, but only plots those with valid prices.
https://usethinkscript.com/threads/...ative-strength-against-spy.12637/#post-113662


info on script()
https://usethinkscript.com/threads/user-defined-function-udf.13414/#post-112610
 
Thread starter Similar threads Forum Replies Date
S 4 color dynamic chart label? Questions 3
Human Dynamic triangular moving average Questions 4
ChaChing Dynamic MacD indicator Questions 1
F Dynamic Labels Questions 5
MP432 Dynamic Response Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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