Custom Scanner for Ascending Wedge

SilasThor

New member
Hello!
I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here: https://usethinkscript.com/threads/...of-the-lines-between-peaks-and-valleys.17406/.

Below is the code for my new indicator.
Code:
#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

def na = double.nan;
def bn = barnumber();
def n = 200;

#find peaks/valleys
def op1 = open;
def hi1 = high;
def lo1 = low;
def cl1 = close;

input magnitude = 6;
def lastxbars = !isnan(getvalue(close, -(magnitude-1)));

def peak1 = hi1 > Highest(hi1[1], magnitude) and hi1 >= Highest(hi1[-magnitude], magnitude);
def valley1 = lo1 < Lowest(lo1[1], magnitude) and lo1 <= Lowest(lo1[-magnitude], magnitude);

#valley points
def y2 = 0.001;
input symbol1_peaks_valleys_dots = yes;
plot zv1 = if symbol1_peaks_valleys_dots and valley1 then lo1*(1-y2) else na;
zv1.SetPaintingStrategy(PaintingStrategy.squares);
zv1.SetDefaultColor(Color.green);
zv1.setlineweight(4);
zv1.hidebubble();

#peak points
plot zp1 = if symbol1_peaks_valleys_dots and peak1 then hi1*(1 +y2) else na;
zp1.SetPaintingStrategy(PaintingStrategy.squares);
zp1.SetDefaultColor(Color.red);
zp1.setlineweight(4);
zp1.hidebubble();

#-----------------------------
#---------- peaks ------------
# if a peak, look for next future peak

def p1nextoff;
def p1nextbn;
def p1nextpr;
def p1slope;
def p1line;
if peak1 then {
# look for offset to next peak
 p1nextoff = fold a = 1 to n
  with p = 1
  while !getvalue(peak1, -a)
  do p + 1;
 p1nextbn = bn + p1nextoff;
 p1nextpr = GetValue(hi1, -p1nextoff);
 p1slope = (p1nextpr - hi1)/p1nextoff;
 p1line = hi1;
} else {
 p1nextoff = p1nextoff[1];
 p1nextbn = p1nextbn[1];
 p1nextpr = p1nextpr[1];
 p1slope = p1slope[1];
 p1line = p1line[1] + p1slope;
}

input test_p1_line = no;
plot z1 = if test_p1_line and p1line > 0 and !isnan(cl1) and lastxbars then p1line else na;
z1.SetDefaultColor(Color.orange);
#-----------------------------
# ------ valley --------------
# if a valley, look for next future valley

def v1nextoff;
def v1nextbn;
def v1nextpr;
def v1slope;
def v1line;
if valley1 then {
# look for offset to next valley
 v1nextoff = fold b = 1 to n
  with q = 1
  while !getvalue(valley1, -b)
  do q + 1;
 v1nextbn = bn + v1nextoff;
 v1nextpr = GetValue(lo1, -v1nextoff);
 v1slope = (v1nextpr - lo1)/v1nextoff;
 v1line = lo1;
} else {
 v1nextoff = v1nextoff[1];
 v1nextbn = v1nextbn[1];
 v1nextpr = v1nextpr[1];
 v1slope = v1slope[1];
 v1line = v1line[1] + v1slope;
}

input test_v1_line = no;
plot z2 = if test_v1_line and v1line > 0 and !isnan(cl1) and lastxbars then v1line else na;
z2.SetDefaultColor(Color.orange);

Then I make a call in my scanner with the following:
Code:
plot scan = peaks_valleys()."v1slope" > peaks_valleys()."p1slope" and peaks_valleys()."v1slope" > 0;

However, the stocks that are returned from the scanner are really a mixed bag, so I was hoping for help on finetuning this. Thanks!
 
Solution
Hello!
I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here: https://usethinkscript.com/threads/...of-the-lines-between-peaks-and-valleys.17406/.

Below is the code for my new indicator.
Code:
#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

def na = double.nan;
def bn = barnumber();
def n = 200;

#find peaks/valleys
def op1 = open;
def hi1 = high;
def lo1 = low;
def cl1 = close;

input magnitude = 6;
def lastxbars = !isnan(getvalue(close...
Hello!
I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here: https://usethinkscript.com/threads/...of-the-lines-between-peaks-and-valleys.17406/.

Below is the code for my new indicator.
Code:
#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

def na = double.nan;
def bn = barnumber();
def n = 200;

#find peaks/valleys
def op1 = open;
def hi1 = high;
def lo1 = low;
def cl1 = close;

input magnitude = 6;
def lastxbars = !isnan(getvalue(close, -(magnitude-1)));

def peak1 = hi1 > Highest(hi1[1], magnitude) and hi1 >= Highest(hi1[-magnitude], magnitude);
def valley1 = lo1 < Lowest(lo1[1], magnitude) and lo1 <= Lowest(lo1[-magnitude], magnitude);

#valley points
def y2 = 0.001;
input symbol1_peaks_valleys_dots = yes;
plot zv1 = if symbol1_peaks_valleys_dots and valley1 then lo1*(1-y2) else na;
zv1.SetPaintingStrategy(PaintingStrategy.squares);
zv1.SetDefaultColor(Color.green);
zv1.setlineweight(4);
zv1.hidebubble();

#peak points
plot zp1 = if symbol1_peaks_valleys_dots and peak1 then hi1*(1 +y2) else na;
zp1.SetPaintingStrategy(PaintingStrategy.squares);
zp1.SetDefaultColor(Color.red);
zp1.setlineweight(4);
zp1.hidebubble();

#-----------------------------
#---------- peaks ------------
# if a peak, look for next future peak

def p1nextoff;
def p1nextbn;
def p1nextpr;
def p1slope;
def p1line;
if peak1 then {
# look for offset to next peak
 p1nextoff = fold a = 1 to n
  with p = 1
  while !getvalue(peak1, -a)
  do p + 1;
 p1nextbn = bn + p1nextoff;
 p1nextpr = GetValue(hi1, -p1nextoff);
 p1slope = (p1nextpr - hi1)/p1nextoff;
 p1line = hi1;
} else {
 p1nextoff = p1nextoff[1];
 p1nextbn = p1nextbn[1];
 p1nextpr = p1nextpr[1];
 p1slope = p1slope[1];
 p1line = p1line[1] + p1slope;
}

input test_p1_line = no;
plot z1 = if test_p1_line and p1line > 0 and !isnan(cl1) and lastxbars then p1line else na;
z1.SetDefaultColor(Color.orange);
#-----------------------------
# ------ valley --------------
# if a valley, look for next future valley

def v1nextoff;
def v1nextbn;
def v1nextpr;
def v1slope;
def v1line;
if valley1 then {
# look for offset to next valley
 v1nextoff = fold b = 1 to n
  with q = 1
  while !getvalue(valley1, -b)
  do q + 1;
 v1nextbn = bn + v1nextoff;
 v1nextpr = GetValue(lo1, -v1nextoff);
 v1slope = (v1nextpr - lo1)/v1nextoff;
 v1line = lo1;
} else {
 v1nextoff = v1nextoff[1];
 v1nextbn = v1nextbn[1];
 v1nextpr = v1nextpr[1];
 v1slope = v1slope[1];
 v1line = v1line[1] + v1slope;
}

input test_v1_line = no;
plot z2 = if test_v1_line and v1line > 0 and !isnan(cl1) and lastxbars then v1line else na;
z2.SetDefaultColor(Color.orange);

Then I make a call in my scanner with the following:
Code:
plot scan = peaks_valleys()."v1slope" > peaks_valleys()."p1slope" and peaks_valleys()."v1slope" > 0;

However, the stocks that are returned from the scanner are really a mixed bag, so I was hoping for help on finetuning this. Thanks!

it is near impossible to debug scan code.
make it a chart study and look for desired signals.


i would forget making a study, and try to make a make a list of words that describe the rules that will define the output.


i changed it to an upper study and added a plot of a true/false pulse signal on top of the candles.


Code:
#scan_Ascending_Wedge_lower

#https://usethinkscript.com/threads/custom-scanner-for-ascending-wedge.21111/
#Custom Scanner for Ascending Wedge
#SilasThor  Jun 19, 2025

#I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here:
#https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/


#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

#declare lower;

def na = double.nan;
def bn = barnumber();
def n = 200;

#find peaks/valleys
def op1 = open;
def hi1 = high;
def lo1 = low;
def cl1 = close;

input magnitude = 6;
def lastxbars = !isnan(getvalue(close, -(magnitude-1)));

def peak1 = hi1 > Highest(hi1[1], magnitude) and hi1 >= Highest(hi1[-magnitude], magnitude);
def valley1 = lo1 < Lowest(lo1[1], magnitude) and lo1 <= Lowest(lo1[-magnitude], magnitude);

#valley points
def y2 = 0.001;
input symbol1_peaks_valleys_dots = yes;
plot zv1 = if symbol1_peaks_valleys_dots and valley1 then lo1*(1-y2) else na;
zv1.SetPaintingStrategy(PaintingStrategy.squares);
zv1.SetDefaultColor(Color.green);
zv1.setlineweight(4);
zv1.hidebubble();

#peak points
plot zp1 = if symbol1_peaks_valleys_dots and peak1 then hi1*(1 +y2) else na;
zp1.SetPaintingStrategy(PaintingStrategy.squares);
zp1.SetDefaultColor(Color.red);
zp1.setlineweight(4);
zp1.hidebubble();

#-----------------------------
#---------- peaks ------------
# if a peak, look for next future peak

def p1nextoff;
def p1nextbn;
def p1nextpr;
def p1slope;
def p1line;
if peak1 then {
# look for offset to next peak
 p1nextoff = fold a = 1 to n
  with p = 1
  while !getvalue(peak1, -a)
  do p + 1;
 p1nextbn = bn + p1nextoff;
 p1nextpr = GetValue(hi1, -p1nextoff);
 p1slope = (p1nextpr - hi1)/p1nextoff;
 p1line = hi1;
} else {
 p1nextoff = p1nextoff[1];
 p1nextbn = p1nextbn[1];
 p1nextpr = p1nextpr[1];
 p1slope = p1slope[1];
 p1line = p1line[1] + p1slope;
}

input test_p1_line = no;
plot z1 = if test_p1_line and p1line > 0 and !isnan(cl1) and lastxbars then p1line else na;
z1.SetDefaultColor(Color.orange);
#-----------------------------
# ------ valley --------------
# if a valley, look for next future valley

def v1nextoff;
def v1nextbn;
def v1nextpr;
def v1slope;
def v1line;
if valley1 then {
# look for offset to next valley
 v1nextoff = fold b = 1 to n
  with q = 1
  while !getvalue(valley1, -b)
  do q + 1;
 v1nextbn = bn + v1nextoff;
 v1nextpr = GetValue(lo1, -v1nextoff);
 v1slope = (v1nextpr - lo1)/v1nextoff;
 v1line = lo1;
} else {
 v1nextoff = v1nextoff[1];
 v1nextbn = v1nextbn[1];
 v1nextpr = v1nextpr[1];
 v1slope = v1slope[1];
 v1line = v1line[1] + v1slope;
}

input test_v1_line = no;
plot z2 = if test_v1_line and v1line > 0 and !isnan(cl1) and lastxbars then v1line else na;
z2.SetDefaultColor(Color.orange);


#Then I make a call in my scanner with the following:
#plot scan = peaks_valleys()."v1slope" > peaks_valleys()."p1slope" and peaks_valleys()."v1slope" > 0;
#plot scan = (v1slope > p1slope and v1slope > 0) * close * 1.1;

def y1 = 0.01;
def rule1 = (v1slope > p1slope and v1slope > 0);
def sig = if rule1 and !rule1[1] then ((close * (1-y1)) + (rule1 * close * (y1*2)))
 else if !rule1 and rule1[1] then (close * (1-y1))
 else sig[1];

plot z = sig;

#plot scan = (close * (1-y1)) + (rule1 * close * (y1*2));

#However, the stocks that are returned from the scanner are really a mixed bag
#
 

Attachments

  • img1.JPG
    img1.JPG
    49.5 KB · Views: 25
Solution

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

Hello!
I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here: https://usethinkscript.com/threads/...of-the-lines-between-peaks-and-valleys.17406/.

Below is the code for my new indicator.
Code:
#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

def na = double.nan;
def bn = barnumber();
def n = 200;

#find peaks/valleys
def op1 = open;
def hi1 = high;
def lo1 = low;
def cl1 = close;

input magnitude = 6;
def lastxbars = !isnan(getvalue(close, -(magnitude-1)));

def peak1 = hi1 > Highest(hi1[1], magnitude) and hi1 >= Highest(hi1[-magnitude], magnitude);
def valley1 = lo1 < Lowest(lo1[1], magnitude) and lo1 <= Lowest(lo1[-magnitude], magnitude);

#valley points
def y2 = 0.001;
input symbol1_peaks_valleys_dots = yes;
plot zv1 = if symbol1_peaks_valleys_dots and valley1 then lo1*(1-y2) else na;
zv1.SetPaintingStrategy(PaintingStrategy.squares);
zv1.SetDefaultColor(Color.green);
zv1.setlineweight(4);
zv1.hidebubble();

#peak points
plot zp1 = if symbol1_peaks_valleys_dots and peak1 then hi1*(1 +y2) else na;
zp1.SetPaintingStrategy(PaintingStrategy.squares);
zp1.SetDefaultColor(Color.red);
zp1.setlineweight(4);
zp1.hidebubble();

#-----------------------------
#---------- peaks ------------
# if a peak, look for next future peak

def p1nextoff;
def p1nextbn;
def p1nextpr;
def p1slope;
def p1line;
if peak1 then {
# look for offset to next peak
 p1nextoff = fold a = 1 to n
  with p = 1
  while !getvalue(peak1, -a)
  do p + 1;
 p1nextbn = bn + p1nextoff;
 p1nextpr = GetValue(hi1, -p1nextoff);
 p1slope = (p1nextpr - hi1)/p1nextoff;
 p1line = hi1;
} else {
 p1nextoff = p1nextoff[1];
 p1nextbn = p1nextbn[1];
 p1nextpr = p1nextpr[1];
 p1slope = p1slope[1];
 p1line = p1line[1] + p1slope;
}

input test_p1_line = no;
plot z1 = if test_p1_line and p1line > 0 and !isnan(cl1) and lastxbars then p1line else na;
z1.SetDefaultColor(Color.orange);
#-----------------------------
# ------ valley --------------
# if a valley, look for next future valley

def v1nextoff;
def v1nextbn;
def v1nextpr;
def v1slope;
def v1line;
if valley1 then {
# look for offset to next valley
 v1nextoff = fold b = 1 to n
  with q = 1
  while !getvalue(valley1, -b)
  do q + 1;
 v1nextbn = bn + v1nextoff;
 v1nextpr = GetValue(lo1, -v1nextoff);
 v1slope = (v1nextpr - lo1)/v1nextoff;
 v1line = lo1;
} else {
 v1nextoff = v1nextoff[1];
 v1nextbn = v1nextbn[1];
 v1nextpr = v1nextpr[1];
 v1slope = v1slope[1];
 v1line = v1line[1] + v1slope;
}

input test_v1_line = no;
plot z2 = if test_v1_line and v1line > 0 and !isnan(cl1) and lastxbars then v1line else na;
z2.SetDefaultColor(Color.orange);

Then I make a call in my scanner with the following:
Code:
plot scan = peaks_valleys()."v1slope" > peaks_valleys()."p1slope" and peaks_valleys()."v1slope" > 0;

However, the stocks that are returned from the scanner are really a mixed bag, so I was hoping for help on finetuning this. Thanks!


here is a different version to experiment with
on the last bar, it calcs the slope between the last 2 peaks. ( and similar for valleys)
bubbles show,
peak slope , offsets to 2 peaks
valley slope , offsets to 2 valleys


Code:
#scan_Ascending_Wedge_lower_01

#https://usethinkscript.com/threads/custom-scanner-for-ascending-wedge.21111/
#Custom Scanner for Ascending Wedge
#SilasThor  Jun 19, 2025

#I am trying to make a scanner to help me find ascending wedge patterns on the 1 minute chart. To do so, I modified an indicator created by @halcyonguy which you can find here:
#https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/


#ref https://usethinkscript.com/threads/compare-2-stocks-find-divergence-of-the-slopes-of-the-lines-between-peaks-and-valleys.17406/
#modified code of halcyonguy

#declare lower;

def na = double.nan;
def bn = barnumber();
def n = 400;

def op = open;
def hi = high;
def lo = low;
def cl = close;


#--------------------------------------------

#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
#def lastbar = (!isnan(close) and isnan(close[-1]));

# define peaks / valleys
# https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
#  Robert Payne
#  https://funwiththinkscript.com
def highx = high;
def lowx = low;
input length = 7;
def offset = Min(length - 1, lastbn - bn);
def peak1 = highx > Highest(highx[1], length - 1) and highx == GetValue(Highest(highx, length), -offset);
def valley1 = lowx < Lowest(lowx[1], length - 1) and lowx == GetValue(Lowest(lowx, length), -offset);

# disable lastbar peaks/valleys
def peak2 = (!lastbar and peak1);
def valley2 = (!lastbar and valley1);

#-------------------------------------



def hi1off;
def hi2off;
def lo1off;
def lo2off;
if bn == 1 then {
 hi1off = 0;
 hi2off = 0;
 lo1off = 0;
 lo2off = 0;
} else if lastbar then {

# find prev peak-------------
 hi1off = fold a = 1 to n
  with b = 1
  while !getvalue(peak1, a)
  do b + 1;

# find 2nd prev peak
 hi2off = fold c = (hi1off + 1) to n
  with d = (hi1off + 1)
  while !getvalue(peak1, c)
  do d + 1;


# find prev valley----------
 lo1off = fold e = 1 to n
  with f = 1
  while !getvalue(valley1, e)
  do f + 1;

# find 2nd prev valley
 lo2off = fold g = (lo1off + 1) to n
  with h = (lo1off + 1)
  while !getvalue(valley1, g)
  do h + 1;

} else {
 hi1off = 0;
 hi2off = 0;
 lo1off = 0;
 lo2off = 0;
}

addchartbubble(lastbar , high,
hi1off + "\n" +
hi2off
, color.yellow, yes);

addchartbubble(lastbar , low,
lo1off + "\n" +
lo2off
, color.yellow, no);


# calc last peak slope, last valley slope
def peak_sl;
def valley_sl;
if lastbar then {
 peak_sl = (getvalue(high,hi1off) - getvalue(high,hi2off)) / (hi2off - hi1off);
 valley_sl = (getvalue(low,lo1off) - getvalue(low,lo2off)) / (lo2off - lo1off);
} else {
 peak_sl = 0;
 valley_sl = 0;
}


addchartbubble(lastbar , high,
peak_sl
, color.yellow, yes);

addchartbubble(lastbar , low,
valley_sl
, color.yellow, no);


#--------------------------------


#valley points
def y2 = 0.001;
input symbol1_peaks_valleys_dots = yes;
plot zv1 = if symbol1_peaks_valleys_dots and valley2 then low*(1-y2) else na;
zv1.SetPaintingStrategy(PaintingStrategy.squares);
zv1.SetDefaultColor(Color.green);
zv1.setlineweight(4);
zv1.hidebubble();

#peak points
plot zp1 = if symbol1_peaks_valleys_dots and peak2 then high*(1 +y2) else na;
zp1.SetPaintingStrategy(PaintingStrategy.squares);
zp1.SetDefaultColor(Color.red);
zp1.setlineweight(4);
zp1.hidebubble();

#
 

Attachments

  • 01-img1.JPG
    01-img1.JPG
    47.7 KB · Views: 23

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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