HOW TO CODE A simple IF

jcostac69

New member
I just want a scanner to identify stocks that are down either 2,3,4 or 5 days in a row. In order to do that, a PARAMETER is required to tell how many days I want to check.

How would you do that?

Thanks in advance for any help.
 
@jcostac69
You can create a custom study based on your scan filters. In a custom study, you can pass through parameters using an input statement.
Then you set up the scanner referencing the custom study.

Someone can provide the exact solution you are looking for if you edit your post to include an image of your scan.
How To Post Images In Your Post
HTH
 

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

@jcostac69 Try this. You can adjust the scan under each case if you need to.
Code:
input c = close;
input days = {default "TWO", "THREE", "FOUR", "FIVE"};
plot scan;
switch (days) {
case "TWO":
    scan = c < c[1] and c[1] < c[2];
case "THREE":
    scan = c < c[1] and c[1] < c[2] and c[2] < c[3];
case "FOUR":
    scan = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4];
case "FIVE":
    scan = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4] and c[4] < c[5];
}
 
Thanks, I have done something similar. But I want something like a PREFILTER in the same code. Could even be a second and or third previous CASE.

i.e Say I want To filter the stocks that are down 50% (a parameter) or more this year since January, went down more than 10% (parameter also) in last X consecutive days (parameter) and have a letter A or B in the symbol. Last one is a nosense filter, I know.

But do all that in just ONE CASE will be a very long condition. And what about if one of the filters is an OR condition.

I hope I got the right explanation.

Regards.
 
@jcostac69 So you want to add more conditions to the scan? If you are then change the plot to def and add your new conditions, 50% down/10% down, and plot the scan. Hope I understood what you meant and what I said makes sense.
Code:
input c = close;
input days = {default "TWO", "THREE", "FOUR", "FIVE"};
def bar;
switch (days) {
case "TWO":
    bar = c < c[1] and c[1] < c[2];
case "THREE":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3];
case "FOUR":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4];
case "FIVE":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4] and c[4] < c[5];
}

##Filter code##

plot scan = bar and #filter condition#;
 
@jcostac69 So you want to add more conditions to the scan? If you are then change the plot to def and add your new conditions, 50% down/10% down, and plot the scan. Hope I understood what you meant and what I said makes sense.
Code:
input c = close;
input days = {default "TWO", "THREE", "FOUR", "FIVE"};
def bar;
switch (days) {
case "TWO":
    bar = c < c[1] and c[1] < c[2];
case "THREE":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3];
case "FOUR":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4];
case "FIVE":
    bar = c < c[1] and c[1] < c[2] and c[2] < c[3] and c[3] < c[4] and c[4] < c[5];
}

##Filter code##

plot scan = bar and #filter condition#;

Dear Generic:
Thank You, you gave enough lights to clear my path.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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