# Scan For Stocks Like This One.

#### Oleron

##### New member
[/URL]

I'm trying to set up a scan to sift out stocks like this one: stocks that are absolutely dead-flat for months, and have very recently begun to exhibit activity. I imagine the reason is obvious =) . Any assistance is appreciated. Thanks.

Solution
Well, I'm not sure since it's early and I haven't had enough coffee yet, but this works for me. I broke the algorithm into steps in the hopes that ToS will deal more elegantly with piecewise calculation and it seems to run just fine.

Code:
``````input n = 15;

def a = Sum(Max(high, close[1]) - Min(low, close[1]), n);
def b = Highest(high, n) - Lowest(low, n);

def c = Log(a/b);

def d = c / Log(n);

plot f = if sum(d > 0.618, n) >= n then 1 else double.nan;``````

I simply replaced the instances of '10' with 'n'. I'm not sure which of them should really have been changed. but it runs. It showed 2 results on the daily scanner as of this morning. (Saturday 20 Nov 2021).

Hope that helps.

-mashume

as an aside: I find, when dealing with long and...
I've some luck with the following code gleaned from a Reddit post:

Code:
``````# Consolidation Scan (Trading Flat)
# Mobius
# To Scan for Flatter Consolidation Raise .618 to .7 and to lengthen or shorten consolidation period raise or lower the value 10.
sum((Log(Sum(Max(high, close[1]) -
Min(low, close[1]), 10) /
(Highest(high, 10) - Lowest(low, 10))) /
Log(10)) > .618, 10) >= 10``````

It's picked out a couple of stocks that seem to fit what I'm looking for, and quite a few more that do not at about a 5/1 ratio. But it's a start.

Code:
``def lngth = 10;``

..in order to make it easier to change the period length, but that single line breaks everything after SUM, and I don't know why. As you can probably tell, I have had only sporadic coding experience, and am a rank beginner at ThinkScript.

Here's another perfect example of what I'm looking for that popped up on FinViz:

The above example would not have been picked up by this code of course because of the recent flurry of trading, and that means it's already too late anyway. I've seen enough of these to know what's going to happen very soon (possibly in the next trading day consider how sharply it has already spiked): it's going to crash. Hard. edited by mods

Last edited by a moderator:
Well, I'm not sure since it's early and I haven't had enough coffee yet, but this works for me. I broke the algorithm into steps in the hopes that ToS will deal more elegantly with piecewise calculation and it seems to run just fine.

Code:
``````input n = 15;

def a = Sum(Max(high, close[1]) - Min(low, close[1]), n);
def b = Highest(high, n) - Lowest(low, n);

def c = Log(a/b);

def d = c / Log(n);

plot f = if sum(d > 0.618, n) >= n then 1 else double.nan;``````

I simply replaced the instances of '10' with 'n'. I'm not sure which of them should really have been changed. but it runs. It showed 2 results on the daily scanner as of this morning. (Saturday 20 Nov 2021).

Hope that helps.

-mashume

as an aside: I find, when dealing with long and complex equations it is almost always better to break them into their basic blocks and calculate those independently rather than as a monolithic block of code. Easier to read, easier to debug. I had to put this one into a text editor and break it down like this:
Code:
``````sum(
(
Log(
Sum(
Max(
high, close[1]
)
-
Min(
low, close[1])
, 10
)
/
(
Highest(
high, 10
)
-
Lowest(
low, 10
)
)
)
/
Log(
10
)
)
> .618,
10
)
>= 10``````
to figure out what went with what, and then I still had to rely on the parenthesis matching of my favourite text editor to get me through. I guess this is my fate having learned mathematics with an RPN HP calculator.

Well, I'm not sure since it's early and I haven't had enough coffee yet, but this works for me. I broke the algorithm into steps in the hopes that ToS will deal more elegantly with piecewise calculation and it seems to run just fine.

Code:
``````input n = 15;

def a = Sum(Max(high, close[1]) - Min(low, close[1]), n);
def b = Highest(high, n) - Lowest(low, n);

def c = Log(a/b);

def d = c / Log(n);

plot f = if sum(d > 0.618, n) >= n then 1 else double.nan;``````

I simply replaced the instances of '10' with 'n'. I'm not sure which of them should really have been changed. but it runs. It showed 2 results on the daily scanner as of this morning. (Saturday 20 Nov 2021).

Hope that helps.

-mashume

as an aside: I find, when dealing with long and complex equations it is almost always better to break them into their basic blocks and calculate those independently rather than as a monolithic block of code. Easier to read, easier to debug. I had to put this one into a text editor and break it down like this:
Code:
``````sum(
(
Log(
Sum(
Max(
high, close[1]
)
-
Min(
low, close[1])
, 10
)
/
(
Highest(
high, 10
)
-
Lowest(
low, 10
)
)
)
/
Log(
10
)
)
> .618,
10
)
>= 10``````
to figure out what went with what, and then I still had to rely on the parenthesis matching of my favourite text editor to get me through. I guess this is my fate having learned mathematics with an RPN HP calculator.

Thank you, that is far more parse-able. Now to see how it works...

87k+ Posts
264 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?