User input to select from multiple options


Category:
0
0

Hi Pete,
I would like to create a drop-down input to select between 3 different numeric options.
I understand that using the switch/case functionality in Thinkscript can achieve this.
Below is the starting code I’m working with. I know it is wrong, I just don’t know how to complete the idea;

input AggressionLevel = {default one, two, three};
def AggressionFactor;
switch (????) {
case one:
AggressionFactor = 1;
case two:
AggressionFactor = 2;
case three:
AggressionFactor = 3;
}

Any help in making this correct would be appreciated. Thank you!

-LT

Marked as spam
Posted by (Questions: 7, Answers: 12)
Asked on November 1, 2023 10:54 pm
152 views
0
Private answer

I had to create my own solution because your example does not result in a fully functioning chart study. Please keep this in mind when posting questions in this forum. Every solution I provide must be geared towards serving the interest of the broadest possible audience.

So you will have to examine my example and determine how to correct your own script to work as you intended. The follow example plots a moving average on the chart. The moving average can be adjusted between an 8 ema, 21 ema or 34 ema by selecting "fast", "medium", or "slow" from the user input named "selectOption".

input selectOption = {default fast, medium, slow};
plot maOne;
switch (selectOption) {
case fast:
maOne = MovingAverage(AverageType.EXPONENTIAL, close, 8);
case medium:
maOne = MovingAverage(AverageType.EXPONENTIAL, close, 21);
case slow:
maOne = MovingAverage(AverageType.EXPONENTIAL, close, 34);
}

For those wishing to learn more about enumerated inputs and switch/case statements in Thinkorswim, the following resources will help:

https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/switch

https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/input/enum

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 2, 2023 8:42 am
0
Thanks Pete, but this does not help me resolve my issue. I am not trying to plot anything. All I would like to do is assign values to the selectable inputs (in this example, one = 1, two = 2, three = 3). Is this possible in Thinkscript?
( at November 2, 2023 8:53 am)
0
Yes, it is certainly possible. You can assign any values you want. And you can change the plot statement to a def statement. However the structure is exactly the same as I have demonstrated.
( at November 2, 2023 8:58 am)
0
Hmmm, do you know why I would be getting these two errors shown in the screenshot below? https://imageupload.io/ib/Kf1iLKWXjDy68DE_1698941315.png ”SelectOption is not a valid enum input” ”Already Assigned: AggressionFactor”
( at November 2, 2023 9:08 am)
0
"selectOption" is a user input from my own solution and is not present in yours. You must substitute it with your own input, which is named "AgressionLevel". All of this would have much easier for you if you had provided a fully functioning section of code which would benefit the rest of our viewers. This is not the place to request one-off solutions which benefit only a single individual.
( at November 2, 2023 9:39 am)