How do I word a scan to look for a criteria that happens twice or more than once?

jngy2k

Member
For example I have the following that I scan for:
(volume>10000000 and close/close[1]>1.04) within 15 bars
It gives me a list of stocks that has volume and is moving by 4% at least one day in the past 15 days.

Now if I want to look for the same criteria (volume>10000000 and close/close[1]>1.04)
BUT to happen TWICE within 15 bars,
then how would I word it??? o_O
 
Ruby:
def MyCondition = volume > 10000000 and close / close[1] > 1.04;
def Count = If MyCondition then Count[1] + 1 else Count[1];
plot Result = Count >= 2;

Custom study filter, select for "Result" to be "Is True" within 15 bars, or how ever you want it.
 
Last edited:
Ruby:
def MyCondition = volume > 10000000 and close / close[1] > 1.04;
def Count = If MyCondition then Count[1] + 1 else Count[1];
plot Result = Count >= 2;

Custom study filter, select for "Result" to be "Is True" within 15 bars, or how ever you want it.
That will work on short-ish lengths, where you might have only one or two hits. If you look at something like daily charts over a year, you may have many many hits, and your counter will only go up and up. It is safer to do it this way:
Ruby:
def MyCondition = volume > 10000000 and close / close[1] > 1.04;
def Count = If MyCondition then 1 else 0;
plot Result = sum(Count, 15) >= 2;
In this version, we create a series of 0 and 1 in Count which we sum over the desired range (15 bars here). Otherwise you will need to specify in your scan to only look at the last 15 days (which I'm not sure how to do... I don't know what length of time scans look back through).

Take the same approach that @Joshua recommended for the custom study, but you don't need the within 15 bars bit as it's specified in the code (in the count() function)

Two approaches, take whichever one works better for the results you need.

Hope that helps,
Mashume
 
@Drmoh1800 It is literally on EG website if you take the time to study his guide and do a proper search so I won't be posting it here.
I just saw this thread and very interested, so registered on Usethinkscript just now. I looked but couldn't find the url to EG Website to study his guide, could you please post it for us? Thanks for your expertise!
 
Just put the code in a lower chart panel...? This will show you if it happened twice or more ever though. If you want it to show if it happens twice or more in a specified period, use the code provided by @mashume
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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