# Create Scanner for stocks that retrace 50% after making HH?

#### ShoNuff

##### New member
Is it possible to create a scanner when a stock make HH and retrace back at least 50%?

Solution
Not sure if it worked.

Not sure. DE came up on the scanner. View attachment 18740

I think I better understand what you are looking for. Try the following code. It makes sure a new higher high was made in the last 10 periods compared with the 10 periods prior. The condition is met when the current close is less than 50% of the highest high averaged with the lowest low in the last 10 periods.

Note:

• I ran this scan, and I found mostly the stocks that seemed to meet your criteria however there were some odd balls. I was able to filter out most of those by making sure I was scanning for stocks above \$10 and with High average volume.
• Play around with the period to get different results. To add more flexibility I added to...
Is it possible to create a scanner when a stock make HH and retrace back at least 50%?View attachment 18732
Code:
``````# Define the period
def period = 10;

# Identify a higher high over the specified period
def HH = high > highest(high[1], period);

# Identify a 50% retracement from the highest high over the specified period
def retracement = close <= (highest(high, period) + lowest(low, period)) / 2;

# Combine the conditions
plot scan = HH and retracement;``````

Code:
``````# Define the period
def period = 10;

# Identify a higher high over the specified period
def HH = high > highest(high[1], period);

# Identify a 50% retracement from the highest high over the specified period
def retracement = close <= (highest(high, period) + lowest(low, period)) / 2;

# Combine the conditions
plot scan = HH and retracement;``````
Not sure if it worked.

Not sure. DE came up on the scanner.

Last edited by a moderator:
Not sure if it worked.

Not sure. DE came up on the scanner. View attachment 18740

I think I better understand what you are looking for. Try the following code. It makes sure a new higher high was made in the last 10 periods compared with the 10 periods prior. The condition is met when the current close is less than 50% of the highest high averaged with the lowest low in the last 10 periods.

Note:

• I ran this scan, and I found mostly the stocks that seemed to meet your criteria however there were some odd balls. I was able to filter out most of those by making sure I was scanning for stocks above \$10 and with High average volume.
• Play around with the period to get different results. To add more flexibility I added to adjustable periods
• Scans are tough because there are a lot of companies that may meet your specific logic but not look great to the human eye. You will have to use your own judgement to filter out the stocks you are not interested in

Code:
``````# Define the period
def recentPeriod = 10;
def distantPeriod = 10;

# Identify a higher high over the specified period
def HH = highest(high[1], recentPeriod) > highest(high[recentPeriod], distantPeriod);

# Identify a 50% retracement from the highest high over the specified period
def retracement = close <= (highest(high, recentPeriod) + lowest(low, recentPeriod)) / 2;

# Combine the conditions
plot scan = HH and retracement;``````

Last edited:
I think I better understand what you are looking for. Try the following code. It makes sure a new higher high was made in the last 10 periods compared with the 10 periods prior. The condition is met when the current close is less than 50% of the highest high averaged with the lowest low in the last 10 periods.

Note:

• I ran this scan, and I found mostly the stocks that seemed to meet your criteria however there were some odd balls. I was able to filter out most of those by making sure I was scanning for stocks above \$10 and with High average volume.
• Play around with the period to get different results. To add more flexibility I added to adjustable periods
• Scans are tough because there are a lot of companies that may meet your specific logic but not look great to the human eye. You will have to use your own judgement to filter out the stocks you are not interested in

Code:
``````# Define the period
def recentPeriod = 10;
def distantPeriod = 10;

# Identify a higher high over the specified period
def HH = highest(high[1], recentPeriod) > highest(high[recentPeriod], distantPeriod);

# Identify a 50% retracement from the highest high over the specified period
def retracement = close <= (highest(high, recentPeriod) + lowest(low, recentPeriod)) / 2;

# Combine the conditions
plot scan = HH and retracement;``````
I love this scan and use the set up a lot. I am so grateful for this simple and important to me thing you created Thank you. I have tried to make the same thing for a lower low... and I just cant think it through (I am using a lookback of 20 periods). This is what I have so far. Can you please check it? I am also really hoping for a watchlist column which will show solid yellow for those on the list that are between the .50 and the .61 retracement. Is there any way you could do this? I would be most grateful indeed.

# Define the period
def recentPeriod = 20;
def distantPeriod = 20;

# Identify a lower low over the specified period
def LL = lowest(low[1], recentPeriod) > lowest(low[recentPeriod], distantPeriod);

# Identify a 50% retracement from the lowest low over the specified period
def retracement = close >= (lowest(low, recentPeriod) + highest(high, recentPeriod)) / 2;

# Combine the conditions
plot scan = LL and retracement;

Last edited:
Can you include into the signal the criteria to also include as an added factor that when the ADX/DMI only signal the 50% retracement when DI- is greater than DI+

# Define the study
declare lower;

# Calculate DI+ and DI- values
def diPlus = DMI(length = adxLength).DIPlus;
def diMinus = DMI(length = adxLength).DIMinus;

# Condition for DI- greater than DI+
def diSignal = diMinus > diPlus;

# Plot the signal
plot signal = diSignal;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.SetLineWeight(3);
signal.SetDefaultColor(Color.GREEN);

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