String inputs for a plot possible?

Yello

New member
Total TOS beginner here, so sorry for this basic question. Is it possible to have string inputs to be used in plot options?

Example:
Code:
input scanOptions = {default "One", "Two", "Three"};

plot scan = OptionOne;
plot scan = OptionTwo;
plot scan = OptionThree;  # just one can be active

I wonder if the switch function can help in some ways. I have no ThinkScript knowledge, but in PHP anything can be done somehow.
 
Solution
Total TOS beginner here, so sorry for this basic question. Is it possible to have string inputs to be used in plot options?

Example:
Code:
input scanOptions = {default "One", "Two", "Three"};

plot scan = OptionOne;
plot scan = OptionTwo;
plot scan = OptionThree;  # just one can be active

I wonder if the switch function can help in some ways. I have no ThinkScript knowledge, but in PHP anything can be done somehow.

your code didn't have any values to plot.

here are 2 methods
i just picked 1,2,3 as something to plot, something to see on a chart when a selection is made in edit studies


Code:
# string_choose
def na = Double.NaN;
input scanOptions = {default "One", "Two", "Three"};

def x;
switch (scanOptions) {
case...

halcyonguy

Well-known member
VIP
Lifetime
Total TOS beginner here, so sorry for this basic question. Is it possible to have string inputs to be used in plot options?

Example:
Code:
input scanOptions = {default "One", "Two", "Three"};

plot scan = OptionOne;
plot scan = OptionTwo;
plot scan = OptionThree;  # just one can be active

I wonder if the switch function can help in some ways. I have no ThinkScript knowledge, but in PHP anything can be done somehow.

your code didn't have any values to plot.

here are 2 methods
i just picked 1,2,3 as something to plot, something to see on a chart when a selection is made in edit studies


Code:
# string_choose
def na = Double.NaN;
input scanOptions = {default "One", "Two", "Three"};

def x;
switch (scanOptions) {
case "One":
    x = close + 1;
case "Two":
    x = close + 2;
case "Three":
    x = close + 3;
}

plot z = x;



Code:
def na = Double.NaN;
input scanOptions = {default "One", "Two", "Three"};

#plot scan = OptionOne;
#plot scan = OptionTwo;
#plot scan = OptionThree;  # just one can be active

plot scan = if scanOptions == scanOptions."One" then close + 1 
  else if scanOptions == scanOptions."Two" then close + 2
  else if scanOptions == scanOptions."Three" then close + 3
  else na;
 
Last edited:
Solution

Yello

New member
Thank you for the reply. Doesn't close refer to closing price?

Some more context.
Right now in the working code all plot scan are # commented out and I need to un-comment the one I want to use. I like to make it a little bit more friendly to use since there are a few options I regularly use.

Code:
input scanOptions = {default "Bull", "Bear"};

plot scan = signalBreakAboveCloud;
plot scan = signalBreakBelowCloud;
 

halcyonguy

Well-known member
VIP
Lifetime
Thank you for the reply. Doesn't close refer to closing price?

Some more context.
Right now in the working code all plot scan are # commented out and I need to un-comment the one I want to use. I like to make it a little bit more friendly to use since there are a few options I regularly use.

Code:
input scanOptions = {default "Bull", "Bear"};

plot scan = signalBreakAboveCloud;
plot scan = signalBreakBelowCloud;


close is the close price on every previous bar.
close is the currest price on the current bar.

my first example that uses switch should work for you...? but we don't know the conditions/variables used to decide what to do.

there is no context in your post.
you haven't said where you want something to happen, chart, column, scan...
i don't know why people post 2 lines of a study and expect a diagnosis ( unless their study is top secret)

by the variable names,
it appears you are plotting boolean values, which is done in a scan. but in a scan , you only use 1 plot statement.

you are guessing at applying functions, plot, strings,..
instead of clearly defining the situation you want to program.
when this happens, do this...
when that happens, do that...

please post the complete code , by clicking on </> icon in the new post header , to open a window, that you can paste in your code.
 

Yello

New member
please post the complete code , by clicking on </> icon in the new post header , to open a window, that you can paste in your code.

Sorry for the confusion. I am not sure I can post the code here, it's free, but may still have some copyrights attached (just don't want to cause or get into trouble). Written by Hahn-Techs Steve Hahn.

https://www.hahn-tech.com/thinkorswim-scan-ichimoku/ (I think this is the direct link)

The code has two parts, a scan (which is here not relevant because for scans you can't use input), but the same code also gives signals as "lower study" in charts. It has like 4 signal options...

#plot scan = signalBreakAboveCloud and signalBullishConfirmation;
#plot scan = signalBreakBelowCloud and signalBearishConfirmation;
#plot scan = trendContinuationLong and signalBullishConfirmation;
#plot scan = trendContinuationShort and signalBearishConfirmation;

And here it gets inconvenient, because I need to unquote the one I want to use. So my maybe naive idea is to have an input field to chose the plot without any code fiddling.
 

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.
Top