Automatic Wedge Pattern Detector for ThinkorSwim

P

PlayTrader

New member
Hi Everyone, brand new to the forum and my coding experience pretty much non existent. I did a search and may have missed it, but @BenTen any tips on how I can take this code and make it into a watchlist column to alert me right when the yellow/white arrows are triggered? I have it in a column now but it is just showing a NaN in the column. I am assuming it is not formatted correctly.

From a blank Scan > Add a study filter > Edit > Delete the default Study > go to thinkScript editor and add the below:

Code:
NameofStudy()."Up4" is true within 2 bars or NameofStudy()."Up5" is true within 3 bars

Press OK > Associate a watch list and or Run the scan > Save

You can change the number of bars to look back from 3 to your choosing. Remember to adjust the aggregate day within the study if you need a different one as the default is set to 1 day.
 
Last edited:
D

dmillz

Member
@PlayTrader @BenTen That doesnt work TOS gives an error about Secondary period not allowed: Day. I had it on day 3 min 5 min etc didnt work, EDIT: So you have to set your Aggregation on the scanner before then set it on the wedge script so it wont show this error.
 
Last edited:
B

bmcgirth

New member
Wondering if the ">" arrows can be reversed in the coding and change the output to a broadening wedge from a narrowing wedge? Can it be something that simple or is it more involved?
thx
 
A

ashfordtrader

New member
Wondering if the ">" arrows can be reversed in the coding and change the output to a broadening wedge from a narrowing wedge? Can it be something that simple or is it more involved?
thx
I am interested in Broadening formation as well. Please help.
 
D

dmillz

Member
anyway to find bullish and bearish wedges. is this possible
 
K

krsheath

New member
VIP
Any one know how to setup a scanner for Bullish Pennant & Falling Wedge
 
rad14733

rad14733

Well-known member
VIP
Any one know how to setup a scanner for Bullish Pennant & Falling Wedge
Have you looked at the Patterns available for Scans...??? Add Filter > Patterns and de-select the ones you don't want to use... Bullish Pennant isn't in the list so you might need to create it using the Pattern Editor... I'll leave it to you to research further in the Learning Center...
 
rad14733

rad14733

Well-known member
VIP
Do you know how to add the pattern ?
I have never done it but I know it is covered in the Learning Center, hence my pointing you there... No need in my learning something I'm not interested in just so I can explain it to you...
 
V

Vorlauf

New member
This one draws the diagonal lines and tell how many candles are in the wedge

Code:
# insidebar345_01

#  add - look for 3 bar pattern

# insidebar45_01

# find 3,4,5 bar , inside bar patterns
# update from  quadinsidebar_01

# start with ver01.  lines for 5 bar
#  copy 5bar code and chg for  3 bar and 4 bar
# disable 2nd agg

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

# quadinsidebar_01
# 2020-06-27
# halcyonguy
#  find a quad inside bar (5 bar pattern)
#    1st bar high, bar 0, is higher than the following 4 bars
#    1st bar low, bar 0, is lower than the following 4 bars
#  draw diagonal and horizontal lines
#    draw lines 3 bars beyond pattern
#    calc slope from 1st bar high to 5th bar high. same with lows
#  draw horizontal lines on a 4 bar pattern
#  draw wedges (samll arrows) on bar0
#



#declare upper;
#declare once_per_bar;


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

#  draw diagonal and horizontal lines on a 5 bar pattern
#  draw lines 3 bars beyond


def na = double.nan;
def hi = high;
def lo = low;

# bar count, indenifier bubble, vert offset
def bubvert = 0.998;

input show_3_bar_pattern = yes;
input show_4_bar_pattern = yes;
input show_5_bar_pattern = yes;

#  plot small arrows above and below bar0
input show_small_arrows_bar0 = yes;

#  plot small arrows above and below last bar
input show_small_arrows_last_bar = yes;

input show_bar_count_bubble = yes;
def sbcb =  show_bar_count_bubble;


# ----- 5 bar inside pattern ---------------------------------

# formulas ref'd off of the 1st bar, bar0, the biggest in the pattern
# find a bar bigger than the next 4 bars
def fivebar0 = show_5_bar_pattern and hi > hi[-1] and hi > hi[-2] and hi > hi[-3] and hi > hi[-4] and lo < lo[-1] and lo < lo[-2] and lo < lo[-3] and lo < lo[-4];

# define the 5 bars in an inside bar
#  as time goes on, look back x+ bars at bar0 to see if it was the biggest candle
def fivebar = fivebar0 or fivebar0[1] or fivebar0[2] or fivebar0[3] or fivebar0[4];


#  plot small arrows above and below bar0
plot v5 = fivebar0 and show_small_arrows_bar0;
v5.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
v5.AssignValueColor(Color.white);
v5.SetLineWeight(1);
v5.hidebubble();
plot w5 = fivebar0 and show_small_arrows_bar0;
w5.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
w5.AssignValueColor(Color.white);
w5.SetLineWeight(1);
w5.hidebubble();


#  plot small arrows above and below last bar
plot s5 = fivebar0[4] and show_small_arrows_last_bar;
s5.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
s5.AssignValueColor(Color.white);
s5.SetLineWeight(1);
s5.hidebubble();
plot t5 = fivebar0[4] and show_small_arrows_last_bar;
t5.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
t5.AssignValueColor(Color.white);
t5.SetLineWeight(1);
t5.hidebubble();

#  sbcb =  show_bar_count_bubble;
addchartbubble(sbcb and fivebar0, (low * bubvert), "5", color.cyan, no);

#  enable slope lines - define bars to draw slope lines.
#  5 bars , and +3 extra bars past the last bar
def en_slope5lines = fivebar or fivebar[1] or fivebar[2] or fivebar[3];

#  calc the slope from 4 gaps, (5 bars)
def bar5gaps = 4;
#  hi slope is neg , lo slope is pos
#  use the 1st bar and last bar to calc slope
def slope5hi2 = (hi[-bar5gaps] - hi[0])/bar5gaps;
def slope5lo2 = (lo[-bar5gaps] - lo[0])/bar5gaps;

#  test data
#addchartbubble(yes,high+0.2, slopehi2 + "\n" + hi[-4] + "\n" + hi[0], color.cyan,yes);
#addchartbubble(yes,low-0.2, slopelo2 + "\n" + lo[-4] + "\n" + lo[0], color.cyan,no);

#  read the slope when fivebar0, and keep it during the 5 bars, and 3 bars after
def slope5hi = if fivebar0 then slope5hi2 else if en_slope5lines then slope5hi[1] else na;
def slope5lo = if fivebar0 then slope5lo2 else if en_slope5lines then slope5lo[1] else na;
# test data  high slope
#addchartbubble(en_slope5lines, high+0.4, slope5hi, color.cyan,yes);

# get barnum at bar0, and keep it during the slope line
def bar0_5number = if fivebar0 then barnumber() else if en_slope5lines then bar0_5number[1] else na;
#addchartbubble(en_slopelines,high+0.2, bar0_number, color.cyan,yes);

#  get the high at bar0, for 5 bar pattern, and keep it during the slope line
def bar0_5high = if fivebar0 then hi else if en_slope5lines then bar0_5high[1] else na;

#  get the low at bar0, for 5 bar pattern, and keep it during the slope line
def bar0_5low = if fivebar0 then lo else if en_slope5lines then bar0_5low[1] else na;

# calc the slope line between 1st and 5th bar highs.
plot diag5hi = if en_slope5lines then ( bar0_5high + (slope5hi * (barnumber() - bar0_5number))) else na;
diag5hi.AssignValueColor(Color.cyan);
diag5hi.SetStyle(Curve.MEDIUM_DASH);
diag5hi.hidebubble();

# calc the slope line between 1st and 5th bar lows.
plot diag5lo = if en_slope5lines then ( bar0_5low + (slope5lo * (barnumber() - bar0_5number))) else na;
diag5lo.AssignValueColor(Color.cyan);
diag5lo.SetStyle(Curve.MEDIUM_DASH);
diag5lo.hidebubble();

# plot a horizontal line at the high of 1st bar
plot horz5hi = if en_slope5lines then bar0_5high else na;
horz5hi.AssignValueColor(Color.cyan);
horz5hi.hidebubble();

# plot a horizontal line at the low of 1st bar
plot horz5lo = if en_slope5lines then bar0_5low else na;
horz5lo.AssignValueColor(Color.cyan);
horz5lo.hidebubble();


# --- 4 bar inside pattern ---------------------------------------


# if a 5 bar exists, dont draw 4 bar lines
#  chk if 4 bar pattern is desired
def draw_4bar = if fivebar then 0 else if show_4_bar_pattern then 1 else 0;

# formulas ref'd off of the 1st bar, bar0, the biggest in the pattern
# find a bar bigger than the next 3 bars
def fourbar0 = draw_4bar and hi > hi[-1] and hi > hi[-2] and hi > hi[-3] and lo < lo[-1] and lo < lo[-2] and lo < lo[-3];
# define the 4 bars in an inside bar
#  as time goes on, look back x+ bars at bar0 to see if it was the biggest candle
def fourbar = fourbar0 or fourbar0[1] or fourbar0[2] or fourbar0[3];

#  plot small arrows above and below bar0
plot v4 = fourbar0 and show_small_arrows_bar0;
v4.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
v4.AssignValueColor(Color.white);
v4.SetLineWeight(1);
v4.hidebubble();
plot w4 = fourbar0 and show_small_arrows_bar0;
w4.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
w4.AssignValueColor(Color.white);
w4.SetLineWeight(1);
w4.hidebubble();

#  plot small arrows above and below last bar
plot s4 = fourbar0[3] and show_small_arrows_last_bar;
s4.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
s4.AssignValueColor(Color.white);
s4.SetLineWeight(1);
s4.hidebubble();
plot t4 = fourbar0[3] and show_small_arrows_last_bar;
t4.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
t4.AssignValueColor(Color.white);
t4.SetLineWeight(1);
t4.hidebubble();

#  sbcb =  show_bar_count_bubble;
addchartbubble(sbcb and fourbar0, (low * bubvert), "4", color.cyan, no);

#  enable slope lines - define bars to draw slope lines.
#  4 bars , and +3 extra bars past the last bar
def en_slope4lines = fourbar or fourbar[1] or fourbar[2] or fourbar[3];

#  calc the slope from 3 gaps, (4 bars)
def bar4gaps = 3;
#  hi slope is neg , lo slope is pos
#  use the 1st bar and last bar to calc slope
def slope4hi2 = (hi[-bar4gaps] - hi[0])/bar4gaps;
def slope4lo2 = (lo[-bar4gaps] - lo[0])/bar4gaps;

#  test data
#addchartbubble(yes,high+0.2, slope4hi2 + "\n" + hi[-4] + "\n" + hi[0], color.cyan,yes);
#addchartbubble(yes,low-0.2, slope4lo2 + "\n" + lo[-4] + "\n" + lo[0], color.cyan,no);

#  read the slope when fourbar0, and keep it during the 4 bars, and 3 bars after
def slope4hi = if fourbar0 then slope4hi2 else if en_slope4lines then slope4hi[1] else na;
def slope4lo = if fourbar0 then slope4lo2 else if en_slope4lines then slope4lo[1] else na;
# test data  high slope
#addchartbubble(en_slope4lines,high+0.4, slope4hi, color.cyan,yes);

# get barnum at bar0, and keep it during the slope line
def bar0_4number = if fourbar0 then barnumber() else if en_slope4lines then bar0_4number[1] else na;
#addchartbubble(en_slope4lines,high+0.2, bar0_4number, color.cyan,yes);

#  get the high at bar0, for 4 bar pattern, and keep it during the slope line
def bar0_4high = if fourbar0 then hi else if en_slope4lines then bar0_4high[1] else na;

#  get the low at bar0, for 4 bar pattern, and keep it during the slope line
def bar0_4low = if fourbar0 then lo else if en_slope4lines then bar0_4low[1] else na;


# calc the slope line between 1st and 4th bar highs.
plot diag4hi = if en_slope4lines then ( bar0_4high + (slope4hi * (barnumber() - bar0_4number))) else na;
diag4hi.AssignValueColor(Color.cyan);
diag4hi.SetStyle(Curve.MEDIUM_DASH);
diag4hi.hidebubble();

# calc the slope line between 1st and 4th bar lows.
plot diag4lo = if en_slope4lines then ( bar0_4low + (slope4lo * (barnumber() - bar0_4number))) else na;
diag4lo.AssignValueColor(Color.cyan);
diag4lo.SetStyle(Curve.MEDIUM_DASH);
diag4lo.hidebubble();

# plot a horizontal line at the high of 1st bar
plot horz4hi = if en_slope4lines then bar0_4high else na;
horz4hi.AssignValueColor(Color.cyan);
horz4hi.hidebubble();

# plot a horizontal line at the low of 1st bar
plot horz4lo = if en_slope4lines then bar0_4low else na;
horz4lo.AssignValueColor(Color.cyan);
horz4lo.hidebubble();


#  --- 3 bar inside pattern -----------


# if a 5 bar or 4 bar exists, dont draw 3 bar lines
#  chk if 3 bar pattern is desired
def draw_3bar = if fivebar or fourbar then 0 else if show_3_bar_pattern then 1 else 0;


# formulas ref'd off of the 1st bar, bar0, the biggest in the pattern
# find a bar bigger than the next 2 bars
def threebar0 = draw_3bar and hi > hi[-1] and hi > hi[-2] and hi > hi[-3] and lo < lo[-1] and lo < lo[-2] and lo < lo[-3];
# define the 3 bars in an inside bar
#  as time goes on, look back x+ bars at bar0 to see if it was the biggest candle
def threebar = threebar0 or threebar0[1] or threebar0[2] or threebar0[3];


#  plot small arrows above and below bar0
plot v3 = threebar0 and show_small_arrows_bar0;
v3.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
v3.AssignValueColor(Color.white);
v3.SetLineWeight(1);
v3.hidebubble();
plot w3 = threebar0 and show_small_arrows_bar0;
w3.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
w3.AssignValueColor(Color.white);
w3.SetLineWeight(1);
w3.hidebubble();


#  plot small arrows above and below last bar
plot s3 = threebar0[3] and show_small_arrows_last_bar;
s3.SetPaintingStrategy(PaintingStrategy.boolean_wedge_UP);
s3.AssignValueColor(Color.white);
s3.SetLineWeight(1);
s3.hidebubble();
plot t3 = threebar0[3] and show_small_arrows_last_bar;
t3.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
t3.AssignValueColor(Color.white);
t3.SetLineWeight(1);
t3.hidebubble();


#  sbcb =  show_bar_count_bubble;
addchartbubble(sbcb and threebar0, (low * bubvert), "3", color.cyan, no);

#  enable slope lines - define bars to draw slope lines.
#  3 bars , and +3 extra bars past the last bar
def en_slope3lines = threebar or threebar[1] or threebar[2] or threebar[3];


#  calc the slope from 2 gaps, (3 bars)
def bar3gaps = 2;
#  hi slope is neg , lo slope is pos
#  use the 1st bar and last bar to calc slope
def slope3hi2 = (hi[-bar3gaps] - hi[0])/bar3gaps;
def slope3lo2 = (lo[-bar3gaps] - lo[0])/bar3gaps;

#  test data
#addchartbubble(yes,high+0.2, slope3hi2 + "\n" + hi[-4] + "\n" + hi[0], color.cyan,yes);
#addchartbubble(yes,low-0.2, slope3lo2 + "\n" + lo[-4] + "\n" + lo[0], color.cyan,no);

#  read the slope when threebar0, and keep it during the 3 bars, and 3 bars after
def slope3hi = if threebar0 then slope3hi2 else if en_slope3lines then slope3hi[1] else na;
def slope3lo = if threebar0 then slope3lo2 else if en_slope3lines then slope3lo[1] else na;
# test data  high slope
#addchartbubble(en_slope3lines,high+0.4, slope3hi, color.cyan,yes);

# get barnum at bar0, and keep it during the slope line
def bar0_3number = if threebar0 then barnumber() else if en_slope3lines then bar0_3number[1] else na;
#addchartbubble(en_slope3lines,high+0.2, bar0_3number, color.cyan,yes);

#  get the high at bar0, for 3 bar pattern, and keep it during the slope line
def bar0_3high = if threebar0 then hi else if en_slope3lines then bar0_3high[1] else na;

#  get the low at bar0, for 4 bar pattern, and keep it during the slope line
def bar0_3low = if threebar0 then lo else if en_slope3lines then bar0_3low[1] else na;


# calc the slope line between 1st and 3rd bar highs.
plot diag3hi = if en_slope3lines then (bar0_3high + (slope3hi * (barnumber() - bar0_3number))) else na;
diag3hi.AssignValueColor(Color.cyan);
diag3hi.SetStyle(Curve.MEDIUM_DASH);
diag3hi.hidebubble();

# calc the slope line between 1st and 3rd bar lows.
plot diag3lo = if en_slope3lines then (bar0_3low + (slope3lo * (barnumber() - bar0_3number))) else na;
diag3lo.AssignValueColor(Color.cyan);
diag3lo.SetStyle(Curve.MEDIUM_DASH);
diag3lo.hidebubble();

# plot a horizontal line at the high of 1st bar
plot horz3hi = if en_slope3lines then bar0_3high else na;
horz3hi.AssignValueColor(Color.cyan);
horz3hi.hidebubble();

# plot a horizontal line at the low of 1st bar
plot horz3lo = if en_slope3lines then bar0_3low else na;
horz3lo.AssignValueColor(Color.cyan);
horz3lo.hidebubble();
#
 

Similar threads

Top