Harmonic Patterns Indicator for ThinkorSwim (ZigZag, Bat, Butterfly, ABCD)

BenTen

BenTen

Administrative
Staff
VIP
This is a multi-harmonic patterns indicator for ThinkorSwim that is consists of 12 different type of patterns including Wolf Wave, Zig Zag, Butterfly, Crab, Elliot Wave, Gartley, and many more.

All of these harmonic and fractals patterns are identified automatically for you. Once the pattern is detected, it will be drawn and labeled right on your chart.

These bearish and bullish patterns can be used to find potential long or short reversal trade ideas.



thinkScript Code

Rich (BB code):
#----------------------------------------------------------------#
#============== Syracusepro Harmonics and Fractals ==============#
#----------------------------------------------------------------#
#===== This program was made with the intention of educational   #
#===== purposes. It contains fractal and harmonic patterns.      #
#===== On the zigzags, the Fibonacci sequence numbers are also   #
#===== included, and shows what makes each patterns valid with   #
#===== their correct names.                                      #
#=========== I hope people interested can make a great program   #
#=========== out of this material. Thanks. ======================#
#----------------------------------------------------------------#

#---------------- Total of 12 Harmonic Patterns -----------------#

#================= Http://www.thinkscriptcode.com ===============#

#---------------------------------------#
#===== Irregular fractals function =====#
#---------------------------------------#
mcdon030 addded tolerance per Larry Pesavento
and roughly 17 more patterns.
script isRegularFractal {
    input mode=0;
    plot ret = if mode == 1 then high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] else if mode == -1 then low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] else 0;
}

#---------------------------------------#
#===== BWilliams fractals function =====#
#---------------------------------------#
script isBWFractal {
    input mode=0;
    plot ret = if mode == 1 then high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] else if mode == -1 then low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] else 0;

}

input showPatterns=Yes;
input showBarColors=No;
input filterBW=No;
input ShowHHLL=No;
input ShowTimeFractals1=No;
input showArrows = No;
input tolerance =.06;
input timeframe1={MIN, TWO_MIN, THREE_MIN, FOUR_MIN, FIVE_MIN, TEN_MIN, FIFTEEN_MIN, TWENTY_MIN, THIRTY_MIN, HOUR, TWO_HOURS, FOUR_HOURS,default DAY, TWO_DAYS, THREE_DAYS, FOUR_DAYS, WEEK, MONTH, OPT_EXP};

input showchannel1=No;
input showchannel2=No;
input showchannel3=No;
input showZigZag=Yes;

def bn=barNumber();
def h2=high[2];
def l2=low[2];

def filteredtopf = if filterBW then isRegularFractal(1) else isBWFractal(1);
def filteredbotf = if filterBW then isRegularFractal(-1) else isBWFractal(-1);

plot TopFractals=filteredtopf[-2];
plot BottomFractals=filteredbotf[-2];
#def TopFractals=filteredtopf[-2];
#def BottomFractals=filteredbotf[-2];

TopFractals.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
TopFractals.SetDefaultColor(color.RED);
BottomFractals.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BottomFractals.SetDefaultColor(color.GREEN );

def b1_0=if bn==0 then -1 else if filteredtopf == 0 then 0 else if b1_0[1]>-1 then b1_0[1]+1 else -1;
def b1_1=b1_0+Getvalue(b1_0,b1_0+1,0)+1;
def b1_2=b1_1+Getvalue(b1_0,b1_1+1,0)+1;

def b2_0=if bn==0 then -1 else if filteredbotf == 0 then 0 else if b2_0[1]>-1 then b2_0[1]+1 else -1;
def b2_1=b2_0+Getvalue(b2_0,b2_0+1,0)+1;
def b2_2=b2_1+Getvalue(b2_0,b1_1+1,0)+1;

def higherhigh = if filteredtopf == 0 or b1_2==b1_1 then 0 else GetValue(high[2],b1_1,0) < GetValue(high[2],b1_0,0) and GetValue(high[2],b1_2,0) < GetValue(high[2],b1_0,0);
def lowerhigh = if filteredtopf == 0 or b1_2==b1_1 then 0 else GetValue(high[2],b1_1,0) > GetValue(high[2],b1_0,0) and GetValue(high[2],b1_2,0) > GetValue(high[2],b1_0,0);
def higherlow = if filteredbotf == 0 or b2_2==b2_1 then 0 else GetValue(low[2],b2_1,0) < GetValue(low[2],b2_0,0) and GetValue(low[2],b2_2,0) < GetValue(low[2],b2_0,0);
def lowerlow = if filteredbotf == 0 or b2_2==b2_1 then 0 else GetValue(low[2],b2_1,0) > GetValue(low[2],b2_0,0) and GetValue(low[2],b2_2,0) > GetValue(low[2],b2_0,0);

AddChartBubble(ShowHHLL and higherhigh,high[-2],"[HH]",color.CYAN,yes);
AddChartBubble(ShowHHLL and lowerhigh,high[-2],"[LH]",color.CYAN,yes);
AddChartBubble(ShowHHLL and higherlow,low[-2],"[HL]",color.GREEN);
AddChartBubble(ShowHHLL and lowerlow,low[-2],"[LL]",color.GREEN);

def hh=if bn==0 then -1 else if higherhigh == 1 then 0 else if hh[1]>-1 then hh[1]+1 else -1;
def ll=if bn==0 then -1 else if lowerlow == 1 then 0 else if ll[1]>-1 then ll[1]+1 else -1;

def higherhhigh = if higherhigh == 0 or hh==-1 then 0 else GetValue(high[2],hh,0) >= high(period=timeframe1) ;
def lowerllow = if lowerlow == 0 or ll==-1 then 0 else GetValue(low[2],ll,0) <= low(period=timeframe1);

AddChartBubble(ShowTimeFractals1 and higherhhigh , high[-2],"[TL]",color.GREEN,yes);
AddChartBubble(ShowTimeFractals1 and lowerllow, low[-2],"[TL]",color.GREEN);

plot TopChannel1=if showchannel1 and filteredtopf then h2[-2] else Double.NaN;
plot BottomChannel1=if showchannel1 and filteredbotf then l2[-2] else Double.NaN;
TopChannel1.SetDefaultColor(color.green);
BottomChannel1.SetDefaultColor(color.red);

TopChannel1.enableApproximation();
BottomChannel1.enableApproximation();

plot TopChannel2=if showchannel2 and higherhigh then h2[-2] else Double.NaN;
plot BottomChannel2=if showchannel2 and lowerlow then l2[-2] else Double.NaN;
TopChannel2.SetDefaultColor(color.BLUE);
BottomChannel2.SetDefaultColor(color.BLUE);

TopChannel2.enableApproximation();
BottomChannel2.enableApproximation();

plot TopChannel3=if showchannel3 and higherhhigh then h2[-2] else Double.NaN;
plot BottomChannel3=if showchannel3 and lowerllow then l2[-2] else Double.NaN;
TopChannel3.SetDefaultColor(color.VIOLET);
BottomChannel3.SetDefaultColor(color.VIOLET);

TopChannel3.enableApproximation();
BottomChannel3.enableApproximation();

addcloud(TopChannel3, BottomChannel3, color.green, color.red);

def istop = if ShowTimeFractals1 then (if higherhhigh  then 1 else 0) else (if filteredtopf then 1 else 0);
def isbot = if ShowTimeFractals1 then (if lowerllow then 1 else 0) else (if filteredbotf then 1 else 0);

def topcount0 = if istop then bn else topcount0[1];
def botcount0 = if isbot then bn else botcount0[1];

def topcount=bn-topcount0;
def botcount=bn-botcount0;

def zigzag = if istop and topcount[1] > botcount[1] then h2 else if isbot and topcount[1] < botcount[1] then l2 else Double.NaN;

#def zz=if showZigZag then zigzag else Double.NaN;
#plot zz=if showZigZag then zigzag else Double.NaN;
plot zz=if showZigZag then zigzag[-2] else Double.NaN;
zz.SetDefaultColor(color.WHITE);
zz.enableApproximation();

AssignPriceColor(if showBarColors and isNaN(zigzag) == 0 then(if h2==zigzag then color.blue else if l2==zigzag then color.CYAN else color.CURRENT) else color.CURRENT);

def z_0=if bn==0 then -1 else if isNaN(zigzag) == 0 then 0 else if z_0[1]>-1 then z_0[1]+1 else -1;
def z_1=z_0+Getvalue(z_0,z_0+1,0)+1;
def z_2=z_1+Getvalue(z_0,z_1+1,0)+1;
def z_3=z_2+Getvalue(z_0,z_2+1,0)+1;
def z_4=z_3+Getvalue(z_0,z_3+1,0)+1;
def z_5=z_4+Getvalue(z_0,z_4+1,0)+1;

#plot rz0=z_0;
#plot rz1=z_1;
#plot rz2=z_2;
#rz0.SetDefaultColor(color.RED);
#plot rgv=Getvalue(z_0,(z_1+1),0);
#rgv.SetDefaultColor(color.GREEN);

#======= Preparing the XABCD Patterns =======#
def x1=GetValue(zigzag,z_5,0);
def x=GetValue(zigzag,z_4,0);
def a=GetValue(zigzag,z_3,0);
def b=GetValue(zigzag,z_2,0);
def c=GetValue(zigzag,z_1,0);
def d=GetValue(zigzag,z_0,0);

#plot rx=x;
#plot ra=a;
#plot rb=b;
#plot rc=c;
#plot rd=d;

#====== Combination to create the patterns ======#

def xab = (AbsValue(b-a)/AbsValue(x-a));
def xad = (AbsValue(a-d)/AbsValue(x-a));
def abc = (AbsValue(b-c)/AbsValue(a-b));
def bcd = (AbsValue(c-d)/AbsValue(b-c));
def xabc = (AbsValue(b-c)/AbsValue(x-a));
def x1xcd = (AbsValue(d-c)/AbsValue(x1-x)); wave5
def x1xab = (AbsValue(b-a)/AbsValue(x1-x)); wave3
def x1xxa = (AbsValue(x-a)/AbsValue(x1-x)); wave2
#===== Checking to see if there is a pattern functions =====#

#---------------------------------------#
#======== Bat Pattern Function =========#
#---------------------------------------#

script isBat {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.382 and xab <= 0.5;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 1.618 and bcd <= 2.618;
    def _xad = xad <= 0.886;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#==== Alternate Bat Pattern Function ===#
#---------------------------------------#

script isAltBat {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab <= 0.382;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 2.0 and bcd <= 3.618;
    def _xad = xad <= 1.13;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#= ==== Butterfly Pattern Function =====#
#---------------------------------------#

script isButterfly {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab <= 0.786;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 1.618 and bcd <= 2.618;
    def _xad = xad >= 1.27 and xad <= 1.618;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#======== ABCD Pattern Function ========#
#---------------------------------------#

script isABCD {
    input _mode=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 1.13 and bcd <= 2.618;
    plot ret =_abc and _bcd and (if _mode == 1 then d < c else d > c);

}

#---------------------------------------#
#====== Gartley Pattern Function =======#
#---------------------------------------#

script isGartley {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.5 and xab <= 0.618;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 1.13 and bcd <= 2.618;
    def _xad = xad >= 0.75 and xad <= 0.875;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#======== Crab Pattern Function ========#
#---------------------------------------#

script isCrab {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.75 and xab <= 0.875;
    def _abc = abc >= 0.382 and abc <= 0.886;
    def _bcd = bcd >= 2.0 and bcd <= 3.618;
    def _xad = xad >= 1.5 and xad <= 1.625;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#======== Shark Pattern Function =======#
#---------------------------------------#

script isShark {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.5 and xab <= 0.875;
    def _abc = abc >= 1.13 and abc <= 1.618;
    def _bcd = bcd >= 1.27 and bcd <= 2.24;
    def _xad = xad >= 0.88 and xad <= 1.13;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#========= 5-0 Pattern Function ========#
#---------------------------------------#

script is5o {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.13 and xab <= 1.618;
    def _abc = abc >= 1.618 and abc <= 2.24;
    def _bcd = bcd >= 0.5 and bcd <= 0.625;
    def _xad = xad >= 0.0 and xad <= 0.236;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#---------------------------------------#
#======= Wolfe Pattern Function ========#
#---------------------------------------#

script isWolf {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.27 and xab <= 1.618;
    def _abc = abc >= 0 and abc <= 5;
    def _bcd = bcd >= 1.27 and bcd <= 1.618;
    def _xad = xad >= 0.0 and xad <= 5;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#-----------------------------------------------#
#===== Head And Shoulders Pattern Function =====#
#-----------------------------------------------#

script isHnS {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 2.0 and xab <= 10;
    def _abc = abc >= 0.90 and abc <= 1.1;
    def _bcd = bcd >= 0.236 and bcd <= 0.88;
    def _xad = xad >= 0.90 and xad <= 1.1;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Con Triangle Harmonic Pattern Function =====#
#--------------------------------------------------#

script isConTria {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.382 and xab <= 0.618;
    def _abc = abc >= 0.382 and abc <= 0.618;
    def _bcd = bcd >= 0.382 and bcd <= 0.618;
    def _xad = xad >= 0.236 and xad <= 0.764;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#-----------------------------------------#
#===== Exp Triangle Pattern Function =====#
#-----------------------------------------#

script isExpTria {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.236 and xab <= 1.618;
    def _abc = abc >= 1.000 and abc <= 1.618;
    def _bcd = bcd >= 1.236 and bcd <= 2.000;
    def _xad = xad >= 2.000 and xad <= 2.236;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}
MCDON's Additions

#--------------------------------------------------#
#===== ABCD Reciprocal Harmonic Pattern Function =====#
#--------------------------------------------------#

script isABCDR {
    input _mode=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _abc = abc >= 1.13 and abc <= 0.786;
    def _bcd = bcd >= .382 and bcd <= .886;
    plot ret =_abc and _bcd and (if _mode == 1 then d < c else d > c);

}

#--------------------------------------------------#
#=====Elliot Wave 5 Harmonic Pattern Function =====#
#--------------------------------------------------#

script isEW5{
    input _mode=0;
    input  x1xxa=0;
    input x1xab=0;
    input abc=0;
    input x1xcd =0;
    input d=0;
    input c=0;
    def _x1xxa = x1xxa  >= .318 and x1xxa  <= .618 ;
    def _x1xab = x1xab >= 1.00 and x1xab <=4.236;
    def _abc =  abc >= 0.318 and abc <= 618;
    def _x1xcd  = x1xcd   >= 1.00 and x1xcd   <= 2.62 ;

    plot ret=_x1xxa and _x1xab and _abc and _x1xcd and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#=====Elliot Wave 4 Harmonic Pattern Function =====#
#--------------------------------------------------#

script isEW4{
    input _mode=0;
    input xab=0;
    input xabc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .318 and xab <= .618 ;
    def _xabc = xabc >= 1.00 and xabc <=4.236;
    def _bcd =  bcd >= 0.318 and bcd <= 618;

    plot ret=_xab and _xabc and _bcd and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#=====GarFly Harmonic Pattern Function =====#
#--------------------------------------------------#

script isGfly{
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .618 and xab <= 0.618 ;
    def _abc = abc >= 0.318 and abc <= .886;
    def _bcd =  bcd >= 1.618 and bcd <= 2.24;
    def _xad =  xad >= 1.272 and xad <= 1.272;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#=====One Two One Harmonic Pattern Function =====#
#--------------------------------------------------#

script isOTO{
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .50 and xab <=.786 ;
    def _abc = abc >= 1.128 and abc <= 3.618;
    def _bcd =  bcd >= .382 and bcd <= .786;
    def _xad =  xad >=.382 and xad <= .786 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#=====Black Swan Harmonic Pattern Function =====#
#--------------------------------------------------#

script isBS{
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.382 and xab <= 2.618 ;
    def _abc = abc >= 0.236 and abc <= .50;
    def _bcd =  bcd >= 1.128 and bcd <= 2.00;
    def _xad =  xad >= 1.128 and xad <= 2.618 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#=====Rectangle Harmonic Pattern Function =====#
#--------------------------------------------------#

script isRect{
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .318 and xab <= .618 ;
    def _abc = abc >= 0.88 and abc <= 1.12;
    def _bcd =  bcd >= 0.88 and bcd <= 1.12;
    def _xad =  xad >= 0.318 and xad <= 0.618 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Ascending and  Descending or "wedge" Harmonic Pattern Function =====#
#--------------------------------------------------#

script isADsc{
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .618 and xab <= .88 ;
    def _abc = abc >= 0.618 and abc <= .88;
    def _bcd =  bcd >= 0.886 and bcd <= 1.13;
    def _xad =  xad >= .01 and xad <= 100;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== ThreeDrives Harmonic Pattern Function =====#
#--------------------------------------------------#

script is3d {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.13 and xab <= 1.618 ;
    def _abc = abc >= 0.50 and abc <= 0.786;
    def _bcd =  bcd >= 1.13 and bcd <= 1.618;
    def _xad =  xad >=1.27 and xad <= 2.618 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Strong Henry Harmonic Pattern Function =====#
#--------------------------------------------------#

script isSHen {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 0.128 and xab <= 261.8 ;
    def _abc = abc >= 0.444 and abc <= 0.618;
    def _bcd =  bcd >= 0.618 and bcd <= .886;
    def _xad =  xad >= .618 and xad <= 1.618 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Contracting Triangle Harmonic Pattern Function =====#
#--------------------------------------------------#

script isContr {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= .318 and xab <= 1.618;
    def _abc =  abc >= .618 and abc <= .886;
    def _bcd =  bcd >= .618 and bcd <= .886 ;
    def _xad =  xad >= .618 and xad <= .886 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Crab 1.618  Harmonic Pattern Function =====#
#--------------------------------------------------#

script isCrab1618 {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = (xab >= 0.382 - tolerance)and (xab <= 0.382+ tolerance) ;
    def _abc =  ( abc >= 0.382- tolerance) and (abc <= 0.618 + tolerance);
    def _bcd =  ( bcd >= 2.24 - tolerance)and (bcd <= 3.618 + tolerance);
    def _xad =  ( xad >= 1.618 - tolerance)and (xad <= 1.618+ tolerance) ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Crab deep  Harmonic Pattern Function =====#
#--------------------------------------------------#

script isCrabd {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = (xab >= 0.886 - tolerance)and (xab <= 0.886 + tolerance) ;
    def _abc =  ( abc >= 0.382- tolerance) and (abc <= 0.886 + tolerance);
    def _bcd =  ( bcd >= 2.618 - tolerance)and (bcd <= 3.618 + tolerance);
    def _xad =  ( xad >= 1.618 - tolerance)and (xad <= 1.618+ tolerance) ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Butterfly 1 Harmonic Pattern Function =====#
#--------------------------------------------------#

script isBut1 {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = (xab >= 0.786 - tolerance) and  (xab >= 0.786+ tolerance) ;
    def _abc =  (abc >= 0.382- tolerance) and( abc <= 0.886+ tolerance);
    def _bcd =  (bcd >= 1.618- tolerance) and(bcd <= 2.618+ tolerance);
    def _xad =  (xad >= 1.27- tolerance) and (xad <= 1.618+ tolerance);
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Butterfly 1113 Harmonic Pattern Function =====#
#--------------------------------------------------#

script isBut2 {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = (xab >= 0.786- tolerance) and (xab <= 2.00+ tolerance);
    def _abc =   (abc >= .618- tolerance) and (abc <= 1.00+ tolerance);
    def _bcd =  ( bcd >= 1.218- tolerance) and (bcd <= 1.218+ tolerance) ;
    def _xad =  (xad >= 1.272- tolerance) and (xad <= 1.272+ tolerance);
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#--------------------------------------------------#
#===== Butterfly alt Harmonic Pattern Function =====#
#--------------------------------------------------#

script isButalt {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = (xab >= 0.382 - tolerance)and (xab <= .618+ tolerance) ;
    def _abc =   (abc >= 1.218- tolerance) and (abc <= 2.618+ tolerance) ;
    def _bcd =  (bcd >= 1.272- tolerance) and (bcd <= 1.272+ tolerance)  ;
    def _xad =  (xad >= .618- tolerance) and (xad <= .786+ tolerance);
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#-----------------------------------------------#
#===== Head And Shoulders Pattern Function =====#
#-----------------------------------------------#

script isHNS1 {
    input _mode=0;
    input tolerance=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.12 and xab <= 3.618;
    def _abc =  abc >= .01 and abc <= 1000;
    def _bcd =  bcd >= .01 and bcd <= .98;
    def _xad =  xad >= .886 and xad <= 1.12;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}

#bears
def u_abcd1=showPatterns and isABCD(-1,abc,bcd,d,c) and isABCD(-1,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abcd1[-2] , high,"Bear ABCD",color.RED,yes);
def u_bat1=showPatterns and isBat(-1,xab,xad,abc,bcd,d,c) and isBat(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bat1[-2] , high,"Bear Bat",color.RED,yes);
def u_abat1=showPatterns and isAltBat(-1,xab,xad,abc,bcd,d,c) and isAltBat(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abat1[-2] , high,"Bear Alt Bat",color.RED,yes);
def u_bfly1=showPatterns and isButterfly(-1,xab,xad,abc,bcd,d,c) and isButterfly(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bfly1[-2] , high,"Bear Butterfly",color.RED,yes);
def u_gley1=showPatterns and isGartley(-1,xab,xad,abc,bcd,d,c) and isGartley(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_gley1[-2] , high,"Bear Gartley",color.RED,yes);
def u_crb1=showPatterns and isCrab(-1,xab,xad,abc,bcd,d,c) and isCrab(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crb1[-2] , high,"Bear Crab",color.RED,yes);
def u_shrk1=showPatterns and isShark(-1,xab,xad,abc,bcd,d,c) and isShark(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_shrk1[-2] , high,"Bear Shark",color.RED,yes);
def u_5o1=showPatterns and is5o(-1,xab,xad,abc,bcd,d,c) and is5o(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_5o1[-2] , high,"Bear 5-O",color.RED,yes);
def u_wlf1=showPatterns and isWolf(-1,xab,xad,abc,bcd,d,c) and isWolf(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_wlf1[-2] , high,"Bear Wolf Wave",color.RED,yes);
def u_hns1=showPatterns and isHns(-1,xab,xad,abc,bcd,d,c) and isHns(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_hns1[-2] , high,"Bear Head and Shoulders",color.RED,yes);
def u_ctr1=showPatterns and isConTria(-1,xab,xad,abc,bcd,d,c) and isConTria(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ctr1[-2] , high,"Bear Contracting Triangle",color.RED,yes);
def u_exp1=showPatterns and isExpTria(-1,xab,xad,abc,bcd,d,c) and isExpTria(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ctr1[-2] , high,"Bear Expanding Triangle",color.RED,yes);
MCDONS Additions
def u_abcdr1=showPatterns and isABCDR(-1,abc,bcd,d,c) and isABCDR(-1,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abcdr1[-2] , high,"Bear Reciprocal",color.RED,yes);
def u_ew51=showPatterns and isEW5(-1,x1xxa,x1xab ,abc, x1xcd,d,c) and isEW5 (-1,x1xxa,x1xab ,abc, x1xcd,d,c)[1]==0;
AddChartBubble(u_ew51[-2] , high,"Bear  Elliot Wave 5",color.RED,yes);
def u_ew1=showPatterns and isEW4(-1,xab,xabc,bcd,d,c) and isEW4 (-1, xab,xabc,bcd,d,c)[1]==0;
AddChartBubble(u_ew1[-2] , high,"Bear  Elliot Wave 4",color.RED,yes);
def u_gf1=showPatterns and isGfly(-1,xab,xad,abc,bcd,d,c) and isGfly(-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_gf1[-2] , high,"Bear  121",color.RED,yes);
def u_oto1=showPatterns and isOTO (-1,xab,xad,abc,bcd,d,c) and isOTO(-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_oto1[-2] , high,"Bear  121",color.RED,yes);
def u_bs1=showPatterns and isBS (-1,xab,xad,abc,bcd,d,c) and isBS(-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bs1[-2] , high,"Bear  BlackSwan",color.RED,yes);
def u_rect1=showPatterns and isRect (-1,xab,xad,abc,bcd,d,c) and isRect (-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_rect1[-2] , high,"Bear  Rectangle",color.RED,yes);
def u_ad1=showPatterns and isADsc (-1,xab,xad,abc,bcd,d,c) and isADsc (-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ad1[-2] , high,"Bear  AscDsc Triangle",color.RED,yes);
def u_3d1=showPatterns and is3d (-1,xab,xad,abc,bcd,d,c) and is3d (-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_3d1[-2] , high,"Bear  Three drives",color.RED,yes);
def u_sh1=showPatterns and isSHen (-1,xab,xad,abc,bcd,d,c) and isSHen (-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_sh1[-2] , high,"Bear  Strong  Henry",color.RED,yes);
def u_con1=showPatterns and isContr(-1,xab,xad,abc,bcd,d,c) and isContr(-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_con1[-2] , high,"Bear Contracting Tri",color.RED,yes);
def u_crabd1=showPatterns and isCrabd(-1,tolerance, xab,xad,abc,bcd,d,c) and isCrabd(-1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crabd1[-2] , high,"Bear Crab Deep",color.RED,yes);
def u_crab16181=showPatterns and isCrab1618(-1,tolerance, xab,xad,abc,bcd,d,c) and isCrab1618(-1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crab16181[-2] , high,"Bear Crab 1.618",color.RED,yes);
def u_but1=showPatterns and isBut1(-1,tolerance, xab,xad,abc,bcd,d,c) and isBut1(-1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_but1[-2] , high,"Bear Butterfly",color.RED,yes);
def u_but21=showPatterns and isBut2(-1,tolerance, xab,xad,abc,bcd,d,c) and isBut2(-1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_but21[-2] , high,"Bear Butterfly 113",color.RED,yes);
def u_hns11=showPatterns and isHNS1(-1, xab,xad,abc,bcd,d,c) and isHNS1(-1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_hns11[-2] , high,"Bear Head and Shoulders",color.RED,yes);

#bulls
def u_abcd2=showPatterns and isABCD(1,abc,bcd,d,c) and isABCD(1,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abcd2[-2] , low,"Bull ABCD",color.GREEN, no);
def u_bat2=showPatterns and isBat(1,xab,xad,abc,bcd,d,c) and isBat(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bat2[-2],low ,"Bull Bat",color.GREEN,no);
def u_abat2=showPatterns and isAltBat(1,xab,xad,abc,bcd,d,c) and isAltBat(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abat2[-2] ,low,"Bull Alt Bat",color.GREEN,no);
def u_bfly2=showPatterns and isButterfly(1,xab,xad,abc,bcd,d,c) and isButterfly(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bfly2[-2] , low,"Bull Butterfly",color.GREEN,no);
def u_gley2=showPatterns and isGartley(1,xab,xad,abc,bcd,d,c) and isGartley(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_gley2[-2] , low,"Bull Gartley",color.GREEN,no);
def u_crb2=showPatterns and isCrab(1,xab,xad,abc,bcd,d,c) and isCrab(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crb2[-2] , low,"Bull Crab",color.GREEN,no);
def u_shrk2=showPatterns and isShark(1,xab,xad,abc,bcd,d,c) and isShark(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_shrk2[-2] , low,"Bull Shark",color.GREEN,no);
def u_5o2=showPatterns and is5o(1,xab,xad,abc,bcd,d,c) and is5o(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_5o2[-2] , low,"Bull 5-O",color.GREEN,no);
def u_wlf2=showPatterns and isWolf(1,xab,xad,abc,bcd,d,c) and isWolf(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_wlf2[-2] , low,"Bull Wolf Wave",color.GREEN,no);
def u_hns2=showPatterns and isHns(1,xab,xad,abc,bcd,d,c) and isHns(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_hns2[-2] , low,"Bull Head and Shoulders",color.GREEN,no);
def u_ctr2=showPatterns and isConTria(1,xab,xad,abc,bcd,d,c) and isConTria(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ctr2[-2] , low,"Bull Contracting Triangle",color.GREEN,no);
def u_exp2=showPatterns and isExpTria(1,xab,xad,abc,bcd,d,c) and isExpTria(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ctr2[-2] , low,"Bull Expanding Triangle",color.GREEN,no);
MCDONS Additions
def u_abcdr2=showPatterns and isABCDR(1,abc,bcd,d,c) and isABCDR(1,abc,bcd,d,c)[1]==0;
AddChartBubble(u_abcdr2[-2] , low,"Bull ABCD Reciprocal",color.GREEN, no);
def u_ew52=showPatterns and isEW5(1,x1xxa,x1xab ,abc, x1xcd,d,c)  and isEW5(1,x1xxa,x1xab ,abc, x1xcd,d,c) [1]==0;
AddChartBubble(u_ew52[-2] , low,"Bull Elliot Wave 5",color.GREEN,no);
def u_ew2=showPatterns and isEW4(1,xab,xabc,bcd,d,c) and isEW4 (1, xab,xabc,bcd,d,c)[1]==0;
AddChartBubble(u_ew2[-2] , low,"Bull Elliot Wave 4",color.GREEN,no);
def u_gf2=showPatterns and isGfly(1,xab,xad,abc,bcd,d,c) and isGfly (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_gf2[-2] , low,"Bull 121",color.GREEN,no);
def u_oto2=showPatterns and isOTO(1,xab,xad,abc,bcd,d,c) and isOTO (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_oto2[-2] , low,"Bull 121",color.GREEN,no);
def u_bs2=showPatterns and isBS(1,xab,xad,abc,bcd,d,c) and isBS (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_bs2[-2] , low,"Bull BlackSwan",color.GREEN,no);
def u_rect2=showPatterns and isRect (1,xab,xad,abc,bcd,d,c) and isRect (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_rect2[-2] , low,"Bull Rectangle",color.GREEN,no);
def u_ad2=showPatterns and isADsc (1,xab,xad,abc,bcd,d,c) and isADsc (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_ad2[-2] , low,"Bull AscDsc Triangle",color.GREEN,no);

def u_3d2=showPatterns and is3d (1,xab,xad,abc,bcd,d,c) and is3d (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_3d2[-2] , low,"Bull ThreeDrives",color.GREEN,no);
def u_sh2=showPatterns and isSHen (1,xab,xad,abc,bcd,d,c) and isSHen (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_sh2[-2] , low,"Bull Strong Henry",color.GREEN,no);
def u_con2=showPatterns and isContr(1,xab,xad,abc,bcd,d,c) and isContr(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_con2[-2] , low,"Bull Contracting Try",color.GREEN,no);
def u_crab16182=showPatterns and isCrab1618(1,tolerance,xab,xad,abc,bcd,d,c) and isCrab1618(1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crab16182[-2] , low,"Bull Crab 1.1618",color.GREEN,no);
def u_crabd2=showPatterns and isCrabd(1,tolerance,xab,xad,abc,bcd,d,c) and isCrabd(1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_crabd2[-2] , low,"Bull Crab Deep",color.GREEN,no);
def u_but2=showPatterns and isBut1(1,tolerance,xab,xad,abc,bcd,d,c) and isBut1(1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_but2[-2] , low,"Bull Butterfly",color.GREEN,no);
def u_but22=showPatterns and isBut2(1,tolerance,xab,xad,abc,bcd,d,c) and isBut2(1,tolerance, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_but22[-2] , low,"Bull Butterfly 113",color.GREEN,no);
def u_hns12=showPatterns and isHNS1(1,xab,xad,abc,bcd,d,c) and isHNS1(1,xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_hns12[-2] , low,"Bull Head and Shoulders",color.GREEN,no);

#============ End Syracusepro Harmonics and Fractals ============#

Shareable Link

 
Last edited:
markos

markos

Active member
VIP
#SyracusePro does some pretty awesome work!#

 
Last edited:
L

Likos

New member
VIP
@BenTen Can you express these names weakest to strongest? From what I see so far, only strong Henry what I could tell by understanding it.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@Likos You can easily do so by backtesting each pattern and looking up their origin. I don't use this at all so I can't rate the patterns.

 
Last edited:
L

Likos

New member
VIP
@BenTen True, I'll take notes.

 
Last edited:
T

tenacity11

Member
VIP
I need some help in isolating a portion of the script into a scan I can do on daily and 15min charts.
The portion I want is the Three Drives. I'd like to have it for three drives to a top and 3 drives to a bottom.
I'd also like to make it an indicator with arrows at the top and bottom of the pattern. Thanks in advance for
any help you can give me.
 
BenTen

BenTen

Administrative
Staff
VIP
@chillc15 ThinkorSwim has a few ZigZag related indicators including the ZigZagPercent.
 
H

horserider

New member
Here you go , all chopped to pieces. Already marks top and bottom of pattern. Did not look at scanning. Dinner time.

Code:
#----------------------------------------------------------------#
#============== Syracusepro Harmonics and Fractals ==============#
#----------------------------------------------------------------#
#===== This program was made with the intention of educational   #
#===== purposes. It contains fractal and harmonic patterns.      #
#===== On the zigzags, the Fibonacci sequence numbers are also   #
#===== included, and shows what makes each patterns valid with   #
#===== their correct names.                                      #
#=========== I hope people interested can make a great program   #
#=========== out of this material. Thanks. ======================#
#----------------------------------------------------------------#

#---------------- Total of 12 Harmonic Patterns -----------------#

#================= Http://www.thinkscriptcode.com ===============#

#---------------------------------------#
#===== Irregular fractals function =====#
#---------------------------------------#
###### mcdon030 addded tolerance per Larry Pesavento
##### and roughly 17 more patterns.
script isRegularFractal {
    input mode=0;
    plot ret = if mode == 1 then high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] else if mode == -1 then low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] else 0;
}

#---------------------------------------#
#===== BWilliams fractals function =====#
#---------------------------------------#
script isBWFractal {
    input mode=0;
    plot ret = if mode == 1 then high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] else if mode == -1 then low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] else 0;

}

input showPatterns=Yes;
input showBarColors=No;
input filterBW=No;
input ShowHHLL=No;
input ShowTimeFractals1=No;
input showArrows = No;
input tolerance =.06;
input timeframe1={MIN, TWO_MIN, THREE_MIN, FOUR_MIN, FIVE_MIN, TEN_MIN, FIFTEEN_MIN, TWENTY_MIN, THIRTY_MIN, HOUR, TWO_HOURS, FOUR_HOURS,default DAY, TWO_DAYS, THREE_DAYS, FOUR_DAYS, WEEK, MONTH, OPT_EXP};

input showchannel1=No;
input showchannel2=No;
input showchannel3=No;
input showZigZag=Yes;

def bn=barNumber();
def h2=high[2];
def l2=low[2];

def filteredtopf = if filterBW then isRegularFractal(1) else isBWFractal(1);
def filteredbotf = if filterBW then isRegularFractal(-1) else isBWFractal(-1);

plot TopFractals=filteredtopf[-2];
plot BottomFractals=filteredbotf[-2];
#def TopFractals=filteredtopf[-2];
#def BottomFractals=filteredbotf[-2];

TopFractals.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
TopFractals.SetDefaultColor(color.RED);
BottomFractals.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BottomFractals.SetDefaultColor(color.GREEN );

def b1_0=if bn==0 then -1 else if filteredtopf == 0 then 0 else if b1_0[1]>-1 then b1_0[1]+1 else -1;
def b1_1=b1_0+Getvalue(b1_0,b1_0+1,0)+1;
def b1_2=b1_1+Getvalue(b1_0,b1_1+1,0)+1;

def b2_0=if bn==0 then -1 else if filteredbotf == 0 then 0 else if b2_0[1]>-1 then b2_0[1]+1 else -1;
def b2_1=b2_0+Getvalue(b2_0,b2_0+1,0)+1;
def b2_2=b2_1+Getvalue(b2_0,b1_1+1,0)+1;

def higherhigh = if filteredtopf == 0 or b1_2==b1_1 then 0 else GetValue(high[2],b1_1,0) < GetValue(high[2],b1_0,0) and GetValue(high[2],b1_2,0) < GetValue(high[2],b1_0,0);
def lowerhigh = if filteredtopf == 0 or b1_2==b1_1 then 0 else GetValue(high[2],b1_1,0) > GetValue(high[2],b1_0,0) and GetValue(high[2],b1_2,0) > GetValue(high[2],b1_0,0);
def higherlow = if filteredbotf == 0 or b2_2==b2_1 then 0 else GetValue(low[2],b2_1,0) < GetValue(low[2],b2_0,0) and GetValue(low[2],b2_2,0) < GetValue(low[2],b2_0,0);
def lowerlow = if filteredbotf == 0 or b2_2==b2_1 then 0 else GetValue(low[2],b2_1,0) > GetValue(low[2],b2_0,0) and GetValue(low[2],b2_2,0) > GetValue(low[2],b2_0,0);

AddChartBubble(ShowHHLL and higherhigh,high[-2],"[HH]",color.CYAN,yes);
AddChartBubble(ShowHHLL and lowerhigh,high[-2],"[LH]",color.CYAN,yes);
AddChartBubble(ShowHHLL and higherlow,low[-2],"[HL]",color.GREEN);
AddChartBubble(ShowHHLL and lowerlow,low[-2],"[LL]",color.GREEN);

def hh=if bn==0 then -1 else if higherhigh == 1 then 0 else if hh[1]>-1 then hh[1]+1 else -1;
def ll=if bn==0 then -1 else if lowerlow == 1 then 0 else if ll[1]>-1 then ll[1]+1 else -1;

def higherhhigh = if higherhigh == 0 or hh==-1 then 0 else GetValue(high[2],hh,0) >= high(period=timeframe1) ;
def lowerllow = if lowerlow == 0 or ll==-1 then 0 else GetValue(low[2],ll,0) <= low(period=timeframe1);

AddChartBubble(ShowTimeFractals1 and higherhhigh , high[-2],"[TL]",color.GREEN,yes);
AddChartBubble(ShowTimeFractals1 and lowerllow, low[-2],"[TL]",color.GREEN);

plot TopChannel1=if showchannel1 and filteredtopf then h2[-2] else Double.NaN;
plot BottomChannel1=if showchannel1 and filteredbotf then l2[-2] else Double.NaN;
TopChannel1.SetDefaultColor(color.green);
BottomChannel1.SetDefaultColor(color.red);

TopChannel1.enableApproximation();
BottomChannel1.enableApproximation();

plot TopChannel2=if showchannel2 and higherhigh then h2[-2] else Double.NaN;
plot BottomChannel2=if showchannel2 and lowerlow then l2[-2] else Double.NaN;
TopChannel2.SetDefaultColor(color.BLUE);
BottomChannel2.SetDefaultColor(color.BLUE);

TopChannel2.enableApproximation();
BottomChannel2.enableApproximation();

plot TopChannel3=if showchannel3 and higherhhigh then h2[-2] else Double.NaN;
plot BottomChannel3=if showchannel3 and lowerllow then l2[-2] else Double.NaN;
TopChannel3.SetDefaultColor(color.VIOLET);
BottomChannel3.SetDefaultColor(color.VIOLET);

TopChannel3.enableApproximation();
BottomChannel3.enableApproximation();

addcloud(TopChannel3, BottomChannel3, color.green, color.red);

def istop = if ShowTimeFractals1 then (if higherhhigh  then 1 else 0) else (if filteredtopf then 1 else 0);
def isbot = if ShowTimeFractals1 then (if lowerllow then 1 else 0) else (if filteredbotf then 1 else 0);

def topcount0 = if istop then bn else topcount0[1];
def botcount0 = if isbot then bn else botcount0[1];

def topcount=bn-topcount0;
def botcount=bn-botcount0;

def zigzag = if istop and topcount[1] > botcount[1] then h2 else if isbot and topcount[1] < botcount[1] then l2 else Double.NaN;

#def zz=if showZigZag then zigzag else Double.NaN;
#plot zz=if showZigZag then zigzag else Double.NaN;
plot zz=if showZigZag then zigzag[-2] else Double.NaN;
zz.SetDefaultColor(color.WHITE);
zz.enableApproximation();

AssignPriceColor(if showBarColors and isNaN(zigzag) == 0 then(if h2==zigzag then color.blue else if l2==zigzag then color.CYAN else color.CURRENT) else color.CURRENT);

def z_0=if bn==0 then -1 else if isNaN(zigzag) == 0 then 0 else if z_0[1]>-1 then z_0[1]+1 else -1;
def z_1=z_0+Getvalue(z_0,z_0+1,0)+1;
def z_2=z_1+Getvalue(z_0,z_1+1,0)+1;
def z_3=z_2+Getvalue(z_0,z_2+1,0)+1;
def z_4=z_3+Getvalue(z_0,z_3+1,0)+1;
def z_5=z_4+Getvalue(z_0,z_4+1,0)+1;

#plot rz0=z_0;
#plot rz1=z_1;
#plot rz2=z_2;
#rz0.SetDefaultColor(color.RED);
#plot rgv=Getvalue(z_0,(z_1+1),0);
#rgv.SetDefaultColor(color.GREEN);

#======= Preparing the XABCD Patterns =======#
def x1=GetValue(zigzag,z_5,0);
def x=GetValue(zigzag,z_4,0);
def a=GetValue(zigzag,z_3,0);
def b=GetValue(zigzag,z_2,0);
def c=GetValue(zigzag,z_1,0);
def d=GetValue(zigzag,z_0,0);

#plot rx=x;
#plot ra=a;
#plot rb=b;
#plot rc=c;
#plot rd=d;

#====== Combination to create the patterns ======#

def xab = (AbsValue(b-a)/AbsValue(x-a));
def xad = (AbsValue(a-d)/AbsValue(x-a));
def abc = (AbsValue(b-c)/AbsValue(a-b));
def bcd = (AbsValue(c-d)/AbsValue(b-c));
def xabc = (AbsValue(b-c)/AbsValue(x-a));
def x1xcd = (AbsValue(d-c)/AbsValue(x1-x));## wave5
def x1xab = (AbsValue(b-a)/AbsValue(x1-x));## wave3
def x1xxa = (AbsValue(x-a)/AbsValue(x1-x));## wave2
#===== Checking to see if there is a pattern functions =====#


#--------------------------------------------------#
#===== ThreeDrives Harmonic Pattern Function =====#
#--------------------------------------------------#

script is3d {
    input _mode=0;
    input xab=0;
    input xad=0;
    input abc=0;
    input bcd=0;
    input d=0;
    input c=0;
    def _xab = xab >= 1.13 and xab <= 1.618 ;
    def _abc = abc >= 0.50 and abc <= 0.786;
    def _bcd =  bcd >= 1.13 and bcd <= 1.618;
    def _xad =  xad >=1.27 and xad <= 2.618 ;
    plot ret=_xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}




#bears


###MCDONS Additions

def u_3d1=showPatterns and is3d (-1,xab,xad,abc,bcd,d,c) and is3d (-1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_3d1[-2] , high,"Bear  Three drives",color.RED,yes);

#bulls


###MCDONS Additions


def u_3d2=showPatterns and is3d (1,xab,xad,abc,bcd,d,c) and is3d (1, xab,xad,abc,bcd,d,c)[1]==0;
AddChartBubble(u_3d2[-2] , low,"Bull ThreeDrives",color.GREEN,no);


#============ End Syracusepro Harmonics and Fractals ============#
 

Top