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

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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

Code:
# HarmonicsAndFractals_v03_Mcdon  # name by JQ
#hint  select either showpatterns or gilmores to declutter.
#----------------------------------------------------------------#
#============== 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 19 more patterns

###### mcdon030 7 more patterns, elliot waves, head and shoulders and bg 90% reversal
###### notes: DUST ETF daily confluence wave4 and hns
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 showgilmore = Yes;
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];
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 zigzag = if istop and topcount[1] > botcount[1] && istop>isbot[1] then h2 else if isbot and topcount[1] < botcount[1] && isbot<istop[1] then l2 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;
def z_6= z_5 + GetValue(z_0, z_5+ 1, 0) + 1;
def z_7 = z_6 + GetValue(z_0, z_6 + 1, 0) + 1;
def z_8 = z_7+ GetValue(z_0, z_7 + 1, 0) + 1;
def z_9 = z_8+ GetValue(z_0, z_8 + 1, 0) + 1;
#======= Preparing the XABCD Patterns =======#
def x1_ = GetValue(zigzag, z_5, 0);   #mcdon
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);
#====== 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));
################ mcdons additions
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
def xabbxd = (AbsValue(bcd ) / AbsValue(xab));
def dcxab = (AbsValue(xab) / AbsValue(bcd ));
def xababc = (AbsValue(xab) / AbsValue(abc));
### time measures
def currentBar = HighestAll(if   !IsNaN(c)
                            then bn
                            else double.nan);
def cp2 = if  a then currentBar-bn else cp2[1];
def cp3 = if  b then currentBar-bn else cp3[1];
def cp4 = if c  then currentBar-bn else cp4[1];
def cp5 = if d then currentBar-bn else cp5[1];
def tp3u =if b then currentBar-cp2  else tp3u[1];
def tp4u =  if c then currentBar-cp3 else tp4u[1] ;
def tp5u = if d then currentBar-cp4 else tp5u[1] ;
def tp25u =  if d then currentBar-cp2 else tp25u [1] ;
#===== 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);
}
#############################33333333333333             MCDON's Additions ##########################
#--------------------------------------------------#
#===== Symmetry Harmonic Pattern Function =====#
#--------------------------------------------------#
script isSymm {
    input _mode = 0;
    input xab = 0;
    input xad = 0;
    input abc = 0;
    input bcd = 0;
    input xabbxd = 0;
    input dcxab = 0;
    input xababc = 0;
    input d = 0;
    input c = 0;
    def _xab = xab >= .382 and xab <= 4.236;
    def _abc = abc >= .1 and abc <= 1000;
    def _bcd = bcd >= .1 and bcd <= 1000;
    def _xad = xad >= .1 and xad <= 1000;
    def _xabbxd = xabbxd >= .50 and xabbxd <= 1.272;
    def _dcxab = dcxab >= .50 and dcxab <= 1.272;
    def _xababc = xababc >= .50 and xababc <= 1.272;
    plot ret = _xab and _abc and _bcd and _xad and _xabbxd and _dcxab and _xababc and (if _mode == 1 then d < c else d > c);
}
#------------------------------------ -----#
#===== Cypher Pattern Function =====#
#-----------------------------------------#
script isCyph {
    input _mode = 0;
    input xab = 0;
    input xad = 0;
    input abc = 0;
    input bcd = 0;
    input d = 0;
    input c = 0;
    def _xab = xab >= .382 and xab <= 0.618;
    def _abc = abc >= 1.13 and abc <= 1.414;
    def _bcd = bcd >= 1.272 and bcd <= 2.000;
    def _xad = xad >= .786 and xad <= .786;
    plot ret = _xab and _abc and _bcd and _xad and (if _mode == 1 then d < c else d > c);
}
#--------------------------------------------------#
#===== 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);
}
#--------------------------------------------------#
#=====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 =====#####    check ratios
#--------------------------------------------------#
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 >= .50 and xab <= .786;
    def _abc = abc >= 0.90 and abc <= 1.1;
    def _bcd =  bcd >= 0.50 and bcd <= .786;
    def _xad =  xad >= .50 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.382 and abc <= 0.886;
    def _bcd =  bcd >= 1.13 and bcd <= 1.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);
}
#--------------------------------------------------#
#===== 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 <= .886;
    def _abc =  abc >= .618 and abc <= .886;
    def _bcd =  bcd >= .618 and bcd <= .886 ;
    def _xad =  xad >= .12 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.13 and xab <= 1000;
    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);
}
#-----------------------------------------------#
#===== Head And Shoulders2   Pattern Function =====#
##added bulkowski strength measures aren't working so just educational
#-----------------------------------------------#
script isHNS3 {
    input _mode = 0;
    input tol = 0;
    input x1 = 0;
    input x = 0;
    input a = 0;
    input b = 0;
    input c = 0;
    input d = 0;
    input tp3u = 0;
    input tp5u = 0;
    input istop =0.0;
    input isbot =0.0;
    def xxa = between(Round((AbsValue(a - x)/ AbsValue(x - x1)),2),(.218 - tol),(.88 + tol)) ;
    def xab = between(Round((AbsValue(b - a)/ AbsValue(a - x)),2),(1.18 - tol),(100 + tol)) ;
    def abc = between(Round((AbsValue(c - b)/ AbsValue(b - a)),2), (.88 - tol),(1.12 + tol)) ;
    def xd = between(Round((AbsValue(d-x) / AbsValue(x)),2),(.001 - tol),(1.005 +tol));
    def bcd = between(Round((AbsValue(d - c) / AbsValue(c - b)),2),(.12 - tol), (.88 + tol)) ;
    def xad = between(Round((AbsValue(d - a) / AbsValue(a - x)),2),(.88 - tol), (1.12 + tol)) ;
    def time = (AbsValue(tp5u) / AbsValue(tp3u));
    def reslope = linearRegressionSlope(vwap);
   def high52w = if d then GetValue(close, GetMaxValueOffset(high, 364), 364 - 1) else high52w[1];##
def low52w = if d then GetValue(close, GetMinValueOffset(low, 364), 364 - 1) else low52w[1];
def bullhl = if max(a,c)<=high52w and min(x,b)<= low52w then 1 else 0;
def bearhl = if max(a,c)>=high52w and min(x,b)>= low52w then 1 else 0;
    def strength1 = (max(a,c)/absvalue((max(a,c)-b)))>=.19 ;  # 20% drop
    def strength2 = (a && istop && a>b) or( a&&isbot &&a<b);  # left shoulder greater then right
    def strength3 =  between(Round((AbsValue(d - c) / AbsValue(b - a)),2),(.0 - tol), (.05 + tol)) or
    Between(time,(1-tol),(1+tol)) ; # symmetry
    def strength4 = reslope<0;  # downward sloping volume n/a
    plot strength = strength1 or strength2  or strength3  or strength4 or (if _mode == 1 then d < c else d > c);
    plot ret = xxa and xab and abc and xd and  bcd and xad and (if _mode == 1 then d < c else d > c);
}
def e_hns3str = yes and isHNS3(-1, tolerance, x1_,x,a,b,c, d, tp3u,tp5u,istop,isbot).strength and isHNS3(-1,tolerance, x1_,x,a,b,c, d, tp3u,tp5u,istop,isbot).strength[1] == 0;
def e_hns3 = yes and isHNS3(-1, tolerance, x1_,x,a,b,c, d, tp3u,tp5u,istop,isbot).ret and isHNS3(-1,tolerance, x1_,x,a,b,c, d, tp3u,tp5u,istop,isbot).ret[1] == 0;
AddChartBubble(e_hns3[-2] , high, "Bear Head and Shoulders v3"+ if e_hns3str  then "Strength : yes" else  " Strength: no", Color.RED, yes);
def u_hns3 = yes and isHNS3(1,tolerance, x1_,x,a,b,c, d, tp3u,tp5u).ret and isHNS3(1,tolerance, x1_,x,a,b,c, d ,tp3u,tp5u).ret[1] == 0;
AddChartBubble(u_hns3[-2] , low, "Bull Head and Shoulders v3 ", Color.GREEN, no);
#= ====Gilmore 90% reversal variation with alma Pattern Function =====#
#---------------------------------------#
script isGilmoreReversal {
   input _mode = 0;
   input x = 0;
   input a = 0;
   input b = 0;
   input c = 0;
   input d = 0;
   input tol = 0;
   input tp3u = 0;
   input tp4u = 0 ;
   input tp5u = 0;
   input tp25u = 0 ;
  def Data = close;
  def Window = 9;
  def Sigma = 6;
  def Offset = 0.85;
  def nRSI = 6;
  def m = (Offset * (Window - 1));
  def s = Window / Sigma;
  def SumVectorData = fold y = 0 to Window with WS do WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(Data, (Window - 1) - y);
  def SumVector = fold z = 0 to Window with CW do CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
def almav = SumVectorData / SumVector;
def NetChgAvg = (almav- almav[1]);
def TotChgAvg = (AbsValue(almav- almav[1]));
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = Round(50 * (ChgRatio + 1), 2);
def fullk = reference StochasticFull().Fullk;
def fullD = reference StochasticFull().FullD;
def ratio = (AbsValue(tp25u) / AbsValue(tp4u));
def ratio1 = (AbsValue(d-a) / AbsValue(c-b));
def ratio2 = (AbsValue(tp5u) / AbsValue(tp3u));
def ratio3 = (AbsValue(d-c) / AbsValue(b-x));
def RVentryt =  Between(ratio,(1.618-tol),(1.618+tol)) or Between(ratio,(2-tol),(2+tol)) or Between(ratio,(3-tol),(3+tol));
def RVentryp =   Between(ratio1,(1.618-tol),(1.618+tol)) or  Between(ratio1,(2-tol),(2+tol)) or Between(ratio1,(3-tol),(3+tol));
def cdabl = Between(ratio2,(1-tol),(1+tol))or Between(ratio3,(1-tol),(1+tol)) ;## length & price degree
def certainbuy = (RVentryt or RVentryp and cdabl) ;
def condi1 = ( certainbuy and RSI <= 5) or (certainbuy and fullk <= 20  ) or (certainbuy and fulld <= 20)  ;
def condi2 =( certainbuy and RSI>= 94) or (certainbuy and fullk>= 80 ) or (certainbuy and fulld >= 80)  ;
def condi3 =(certainbuy and RSI >= 94) or (certainbuy[1] and fullk<= 18.5) or (certainbuy[1] and fulld <= 18.5)  ;
  plot ret = condi1 and (if _mode == 1 then d < c else d > c);
  plot ret1 = condi2 and (if _mode == 1 then d < c else d > c);
}
# gilmore strength measures need cd=xa or bc=xa in time or price and crosses, such as falsebreak, reverse, inside , outside and double.

###################    redefine values for complex Elliot waves  ###########################
############################################################################################
def x1 = z_0 + GetValue(z_0, z_0 + 1, 0) + 1;
def x2 = z_1 + GetValue(z_0, z_1 + 1, 0) + 1;
def x3 = z_2 + GetValue(z_0, z_2 + 1, 0) + 1;
def x4 = z_3 + GetValue(z_0, z_3 + 1, 0) + 1;
def x5 = z_4 + GetValue(z_0, z_4 + 1, 0) + 1;
def x6= z_5 + GetValue(z_0, z_5+ 1, 0) + 1;
def x7 = z_6 + GetValue(z_0, z_6 + 1, 0) + 1;
def x8 = z_7+ GetValue(z_0, z_7 + 1, 0) + 1;
def x9 = z_8+ GetValue(z_0, z_8 + 1, 0) + 1;
def x10 = z_9+ GetValue(z_0, z_9 + 1, 0) + 1;
#--------------------------------------------------#
#=====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);
}
#---------------------------------------#
#======== EW 5 abc or greater cycle 2 Structure Pattern Function =========#
#---------------------------------------#
script isEW {
    input _mode = 0;
    input tol = 0;
    input x1 = 0;
    input x2 = 0;
    input x3 = 0;
    input x4  = 0;
    input x5 = 0;
    input x6 = 0;
    input x7  = 0;
    input x8 = 0;
    input x9 = 0;
    def uwcr = Round((AbsValue(x1 - x2) / AbsValue(x3 - x4)),2);
    def uwbr = Round((AbsValue(x2 - x3) / AbsValue(x3 - x4)),2);
    def uwar = Round((AbsValue(x3 - x4) / AbsValue(x4 - x9)),2);
    def uw5r = Round((AbsValue(x4 - x5) / AbsValue(x8 - x9)),2);
    def uw4r = Round((AbsValue(x5 - x6) / AbsValue(x6 - x7)),2);
    def uw3r = Round((AbsValue(x6 - x7) / AbsValue(x8 - x9)),2);
    def uw2r = Round((AbsValue(x7 - x8) / AbsValue(x8 - x9)),2);
    def _uwcr = Between(uwcr, (.50-tol), (2.618+tol)) ;
    def _uwbr = Between(uwbr,(.382-tol), (1.236+tol)) and uwar<=(.99) ;
    def _uw5r = Between(uw5r, (1.14-tol), (4.236+tol));
    def _uw4r = Between(uw4r,(.24-tol), (.886+tol)) ;
    def _uw3r = Between(uw3r, (1.14-tol), (4.23+tol)) ;
   def _uw2r = Between(uw2r, (.24-tol), (0.854+tol));
    plot ret = _uwcr and _uwbr and _uw5r and _uw4r  and _uw3r and  _uw2r and  (if _mode == 1 then x1 < x2 else x1> x2);
}
#---------------------------------------#
#======== EW   5    wave 4 correction is abc  Structure Pattern Function =========#
#---------------------------------------#
script isEW4abc {
    input _mode = 0;
    input tol = 0;
    input x1 = 0;
    input x2 = 0;
    input x3 = 0;
    input x4  = 0;
    input x5 = 0;
    input x6 = 0;
    input x7  = 0;
    input x8 = 0;
    input x9 = 0;
    def we45 = Round((AbsValue(x1 - x2) / AbsValue(x7 - x8)),2);
    def we4c = Round((AbsValue(x2 - x3) / AbsValue(x4 - x5)),2);
    def we4b = Round((AbsValue(x3 - x4) / AbsValue(x4 - x5)),2);
    def we44 = Round((AbsValue(x2 - x5) / AbsValue(x5 - x6)),2);
    def we43 = Round((AbsValue(x5 - x6) / AbsValue(x7 - x8)),2);
    def we42 = Round((AbsValue(x6 - x7) / AbsValue(x7 - x8)),2);
    def _we45 =Between(we45, (1-tol), (4.236+tol)) ;
    def _we4c = Between(we4c,(.50-tol), (2.618+tol));
    def _we4b = Between(we4b, (.382-tol), (1.236+tol));
    def _we44 = Between( we44,(.24-tol), (.886+tol)) ;
    def _we43= Between(we43, (1.14-tol), (4.23+tol)) ;
    def _we42 = Between(we42, (.24-tol), (0.854+tol));;
    plot ret = _we45 and _we4c and _we4b and _we44 and _we43 and  _we42 and  (if _mode == 1 then x1 < x2 else x1> x2);
}

#---------------------------------------#
#======== EW   5    wave 3 is extension Structure Pattern Function =========#
#---------------------------------------#
script isEW5ext3 {
    input _mode = 0;
    input tol = 0;
    input x1 = 0;
    input x2 = 0;
    input x3 = 0;
    input x4  = 0;
    input x5 = 0;
    input x6 = 0;
    input x7  = 0;
    input x8 = 0;
    input x9 = 0;
    input x10 = 0;
    def w5er = Round((AbsValue(x1 - x2) / AbsValue(x9 - x10)),2);
    def w4er = Round((AbsValue(x2 - x3) / AbsValue(x3 - x8)),2);
    def w3er = Round((AbsValue(x3 - x8) / AbsValue(x9 - x10)),2);
    def w35er = Round((AbsValue(x3 - x4) / AbsValue(x7 - x8)),2);
    def w34er = Round((AbsValue(x4 - x5) / AbsValue(x5 - x6)),2);
    def w33er = Round((AbsValue(x5 - x6) / AbsValue(x7 - x8)),2);
    def w32er = Round((AbsValue(x6 - x7) / AbsValue(x7 - x8)),2);
    def w2er = Round((AbsValue(x8 - x9) / AbsValue(x9 - x10)),2);
    def _w5er =Between(w5er, (1-tol), (4.236+tol)) ;
    def _w4er= Between( w4er,(.24-tol), (.886+tol));
    def _w3er = Between(w3er, (1.14-tol), (4.236+tol));
    def _w35er = Between(w35er,(1-tol), (4.236+tol));
    def _w34er= Between(w34er, (.24-tol), (.854+tol));
    def _w33er = Between(w33er, (1.14-tol), (4.236+tol));
    def _w32er = Between(w32er, (.24-tol), (.618+tol));
    def _w2er =Between(w2er , (.24-tol), (0.854+tol));
    plot ret = _w5er and _w4er and _w3er and _w35er and _w34er and  _w33er and   _w32er and  _w2er and (if _mode == 1 then x1 < x2 else x1> x2);
}
#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_exp1[-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_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);
def u_isSymm1 = showPatterns and isSymm(-1, xab, xad, abc, bcd, xabbxd, dcxab, xababc, d, c) and isSymm(-1, xab, xad, abc, bcd, xabbxd, dcxab, xababc, d, c)[1] == 0;
AddChartBubble(u_isSymm1[-2] , high, "bear Symmetry",Color.RED, yes);
def u_isCyph1 = showPatterns and isCyph(-1, xab, xad, abc, bcd, d, c) and isCyph(-1, xab, xad, abc, bcd, d, c)[1] == 0;
AddChartBubble(u_isCyph1[-2] , high, "bear Cypher", Color.RED, yes);
def e_isGilmoreReversal = showgilmore  and isGilmoreReversal (-1, x, a, b, c, d,tolerance,  tp3u,tp4u,tp5u,tp25u).ret1 and isGilmoreReversal (-1, x, a, b, c, d,tolerance,  tp3u,tp4u,tp5u,tp25u).ret1[1] == 0;
AddChartBubble(e_isGilmoreReversal[-2] , high, " bear isGilmoreReversal  ", 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_isEW1 = showgilmore  and isEW(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9) and isEW(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9)[1] == 0;
AddChartBubble(u_isEW1[-2],high, "bear Elliot 5 abc ", Color.red, no);
def u_isEW4abc1 = showgilmore  and isEW4abc(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9) and isEW4abc(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9)[1] == 0;
AddChartBubble(u_isEW4abc1[-2]  ,high, "bear Elliot 5 wv4= abc ", Color.red, no);
def u_isEW5ext31 = showgilmore  and isEW5ext3(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) and isEW5ext3(-1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)[1] == 0;
AddChartBubble(u_isEW5ext31[-2] ,high, "bear Elliot 5 extend wave 3 ", Color.red, no);
#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_exp2[-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 = showgilmore  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 = showgilmore  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 = showgilmore  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);
def u_isSymm2 = showPatterns and isSymm(1, xab, xad, abc, bcd, xabbxd, dcxab, xababc, d, c) and isSymm(1, xab, xad, abc, bcd, xabbxd, dcxab, xababc, d, c)[1] == 0;
AddChartBubble(u_isSymm2[-2] , low, "bull Symmetry   "  , Color.GREEN, no);
def u_isCyph2 = showPatterns and isCyph(1, xab, xad, abc, bcd, d, c) and isCyph(1, xab, xad, abc, bcd, d, c)[1] == 0;
AddChartBubble(u_isCyph2[-2] , low, "bull Cypher" , Color.GREEN, no);
def u_isGilmoreReversal = showgilmore  and isGilmoreReversal(1,  x, a, b, c, d,tolerance,  tp3u,tp4u,tp5u,tp25u ) and isGilmoreReversal(1,  x, a, b, c, d,tolerance,  tp3u,tp4u,tp5u,tp25u)[1] == 0;
AddChartBubble(u_isGilmoreReversal[-2] , low, " bull isGilmoreReversal", Color.GREEN, no);

def u_isEW4abc2 = showgilmore  and isEW4abc(1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9) and isEW4abc(1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9)[1] == 0;
AddChartBubble( u_isEW4abc2[-2] , low, "bull Elliot 5 wv4 = abc  ", Color.GREEN, no);
def u_isEW5ext32 = showgilmore  and isEW5ext3(1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) and isEW5ext3(1,tolerance,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)[1] == 0;
AddChartBubble( u_isEW5ext32[-2] , low, "bull Elliot 5 extend wave 3  ", Color.GREEN, no);

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

Shareable Link


Video Tutorial

 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
#SyracusePro does some pretty awesome work!#

 
Last edited:
L

Likos

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
Warehouse
@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

Member
VIP
@BenTen True, I'll take notes.

 
Last edited:
tenacity11

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
Warehouse
@chillc15 ThinkorSwim has a few ZigZag related indicators including the ZigZagPercent.
 
H

horserider

Active member
Warehouse
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 ============#
 
C

chillc15

New member
Another ZIGZAG. In need of some help. I would like to be able to select my own colors for the indicated vertical "buy" lines. Instead of the
red-green vertical lines I want to be able to select any color. It uses the defineglobalcolor and I am afraid if I mess with that I may screw up some of the actual code. Is there anyway to also change the red "Buy" which is actually calling for a short and use the word "Sell". Any assistance is appreciated. Thanks.

Code:
# https://researchtrade.com/forum/read.php?7,2258,7937#msg-7937
# OptionMaster_ZIGZAG_Signal
#
input price = close;

input priceH = high; # swing high

input priceL = low; # swing low

input ATRreversalfactor = 3.2;

def ATR = reference ATR(length = 5);

def reversalAmount = ATRreversalfactor * ATR;

input showlines = yes;

input displace = 1;

input showBubbleschange = yes;

def barNumber = BarNumber();

def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};

rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {

minMaxPrice = price;

state = state.undefined;

} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {

if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {

state = state.downtrend;

minMaxPrice = priceL;

} else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {

state = state.uptrend;

minMaxPrice = priceH;

} else {

state = state.undefined;

minMaxPrice = GetValue(minMaxPrice, 1);

}

} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {

if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {

state = state.downtrend;

minMaxPrice = priceL;

} else {

state = state.uptrend;

minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));

}

} else {

if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {

state = state.uptrend;

minMaxPrice = priceH;

} else {

state = state.downtrend;

minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));

}

}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;

def futureDepth = barCount - barNumber;

def tmpLastPeriodBar;

if (isCalculated) {

if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {

tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1

while lastPeriodBarAcc > 0

do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))

then -lastPeriodBarAcc

else lastPeriodBarAcc + 1;

} else {

tmpLastPeriodBar = 0;

}

} else {

tmpLastPeriodBar = Double.NaN;

}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;

rec currentPoints;

if (state == state.uptrend and isCalculated) {

currentPriceLevel =

fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice

do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));

currentPoints =

fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN

while IsNaN(maxPointOnPeriodAcc)

do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)

then maxPointOnPeriodI

else maxPointOnPeriodAcc;

} else if (state == state.downtrend and isCalculated) {

currentPriceLevel =

fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice

do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));

currentPoints =

fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN

while IsNaN(minPointOnPeriodAcc)

do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)

then minPointOnPeriodI

else minPointOnPeriodAcc;

} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {

currentPriceLevel = GetValue(currentPriceLevel, 1);

currentPoints = GetValue(currentPoints, 1) + 1;

} else {

currentPoints = 1;

currentPriceLevel = GetValue(price, currentPoints);

}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave = if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;

#Higher/Lower/Equal High, Higher/Lower/Equal Low

def xxhigh = if zzSave == priceH then Round(high, 2) else Round(xxhigh[1], 2);

def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2);

def xxlow = if zzSave == priceL then Round(low, 2) else Round(xxlow[1], 2);

def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2);

rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));

"ZZ$".EnableApproximation();

"ZZ$".DefineColor("Up Trend", Color.UPTICK);

"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);

"ZZ$".DefineColor("Undefined", Color.WHITE);

"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" ));

DefineGlobalColor("Unconfirmed", Color.WHITE);

DefineGlobalColor("Up", Color.UPTICK);

DefineGlobalColor("Down", Color.DOWNTICK);

AddVerticalLine(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, "Buy", if barCount ==

barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Down" ) else GlobalColor("Up" ),curve.FIRM);

## END CODE
 
H

horserider

Active member
Warehouse
@chillc15 I have seen a third version of this that gave a confirmed signal after a buy or sell. All the same, BenTen reversal, the one you posted and the other I mentioned, all repaint. So not worth the effort to modify the display of the code.
 
C

chillc15

New member
@chillc15 I have seen a third version of this that gave a confirmed signal after a buy or sell. All the same, BenTen reversal, the one you posted and the other I mentioned, all repaint. So not worth the effort to modify the display of the code.
I think the zig gets a bad rap simply based on the repainting but it also depends on the trader, the instrument he is trading, time frame and goals. Everyone should have a trading plan and not just simply going by this indicator or that. Again depending on time frame other elements also have to be taken into consideration like 50 day, 200, volume etc.. But I am sure I am not telling you anything you don't already know. I am actually testing several different atr reversal numbers and was able to figure the colors out for the verticals. I would be interested in seeing the thrid version you mentioned if you have it.
 
H

horserider

Active member
Warehouse


@chillc15 Ok here is the other version. Has some other features. If you can make a consistent strategy out of these various zigzag types please let me know.

Code:
## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from
## Thinkorswim ZigZagSign Script
## Mods by Larry to add chart bubbles & horizontal lines
## Mod by Larry to add Chart Bubble  for HH/LL indication
## 7.1.13 Added Volume Wave (similar looking to other Wave Volume studies) as a lower study. To use this, just load 2 versions of this study and designate one for the upper panel and one for the lower panel. For the lower panel, select input showvolumewave == yes. For the upper panel input showvolumewave ==no and then select the other options as usual.
##7.27.13 Added 2nd Zigzag from new TOS ZigZagHighLow indicator (can see smaller zigzags if used)
##8.24.13 Mod by Lar to add Supply/Demand Levels (Red Zones are Supply, Green are Demand), ability to enter percentage, amount or atr for reversalAmount (using the greater of the three at any reversal)

def   price               = close;
def   priceH              = high;    # swing high
def   priceL              = low;     # swing low
input ATRreversalfactor   = 3.0;#Hint ATRreversalfactor: 3 is standard, adjust to whatever instrument/timeframe you are trading.
input ATRlength           = 5;#Hint ATRlength: 5 is standard, adjust to whatever instrument/timeframe you are trading
input useatr              = yes;#Hint useatr: set to no to use manual zigzagamount for reversalamount before a new zigzag is drawn. The ATR will still be used for auto fibs.
input zigzagpercent       = 0.20;
input zigzagamount        = .15;
def ATR                   = reference ATR(length = ATRlength);
#def reversalAmount        = if useatr == yes then ATRreversalfactor * ATR else zigzagamount;
def reversalAmount        = if (close * zigzagpercent / 100) > Max(zigzagamount < ATRreversalfactor * ATR, zigzagamount) then (close * zigzagpercent / 100) else if zigzagamount < ATRreversalfactor * ATR then ATRreversalfactor * ATR else zigzagamount;
#addlabel(yes,(zigzagpercent*close/100)+"   "+zigzagamount+"  "+(atrreversalfactor*ATR));
input showsupplydemand    = no;
input showhorizontal      = no;#Hint showhorizontal: set yes to display horizontal lines at low/high of each zigzag high/low reversal bar to use for possible entry point
input bubbleoffset        = .0005;
input pricecolor          = no;
input showVolumeWave      = no;#Hint showvolumewave: set all other bubbles to no if showvolumeWave is selected yes
input showcombinedbubble  = no;#Hint showcombinedbubble: set other bubbles contained in combined to no if combined selected yes
input showcombinedbubble2 = no;#Hint showcombinedbubble2: shorter version. set other bubbles contained in combined to no if combined selected yes
input showBubbleshhll     = no;
input showBubblesprice    = no;
input showBubbleschange   = no;
input showBubblesbarcount = no;
input showBubblesVolume   = no;
input showFibLines        = no;
input showFibExtLines     = yes;
input usemanualfibskip    = no;#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.
input fibskip             = .50;#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.
input showBubblesfibratio = no;
input showFibLabel        = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
input fib1level           = .236;
input fib2level           = .382;
input fibMlevel           = .500;
input fib3level           = .618;
input fib4level           = .786;
input showArrows          = no;
input useAlerts           = no;
input showconfirmedLabel  = yes;#Hint showconfirmedLabel: Select yes to see current status of ZigZag, either unconfirmed or confirmed
input showBubblewaveC     = no;#Hint showbubblewave123: Not complete, work in progress

#Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

#Original TOS ZigZag code Modified by Linus
def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
    minMaxPrice = price;
    state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.undefined;
        minMaxPrice = GetValue(minMaxPrice, 1);
    }
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else {
        state = state.uptrend;
        minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
    }
} else {
    if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.downtrend;
        minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
    }
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth =  barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
    if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
        tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1
            while lastPeriodBarAcc > 0
            do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
                then -lastPeriodBarAcc
                else lastPeriodBarAcc + 1;
    } else {
        tmpLastPeriodBar = 0;
    }
} else {
    tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
    currentPriceLevel =
        fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice
            do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));
    currentPoints =
        fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN
            while IsNaN(maxPointOnPeriodAcc)
            do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
                then maxPointOnPeriodI
                else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
    currentPriceLevel =
        fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice
            do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));
    currentPoints =
        fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN
            while IsNaN(minPointOnPeriodAcc)
            do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
                then minPointOnPeriodI
                else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {
    currentPriceLevel = GetValue(currentPriceLevel, 1);
    currentPoints = GetValue(currentPoints, 1) + 1;
} else {
    currentPoints = 1;
    currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave =  if !IsNaN("ZZ$") then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and  state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);
def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;
rec isConf =  AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1)) ;
rec isconfreal = if isConf[1] == 0 and isConf then close else Double.NaN;
"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.GREEN);
"ZZ$".DefineColor("Down Trend", Color.RED);
"ZZ$".DefineColor("Undefined", Color.YELLOW);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined") else if isUp then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend"));
"ZZ$".SetLineWeight(2);
DefineGlobalColor("Unconfirmed", Color.YELLOW);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);

#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2  != zzsave2[1]  then zzsave2[1]  else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];
rec priorzz4 = if priorzz3 != priorzz3[1] then priorzz3[1] else priorzz4[1];
rec priorzz5 = if priorzz4 != priorzz4[1] then priorzz4[1] else priorzz5[1];
rec priorzz6 = if priorzz5 != priorzz5[1] then priorzz5[1] else priorzz6[1];

rec upmove = if currentPoints == 0 and upmove[1] == 0 then 1 else if upmove[1] == 1  and currentPoints != 0  then 1 else 0;
rec dnmove = if currentPoints == 0 and upmove[1] == 1 then 1 else if dnmove[1] == 1 and currentPoints != 0  then 1 else 0;

def extfib1 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1 else extfib1[1];
plot extfib100 = if showFibExtLines and currentPoints != 0 and upmove and !IsNaN(extfib1) then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
def extfib2 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 0.618 else extfib2[1];
plot extfib618 = if showFibExtLines and currentPoints != 0 and upmove and !IsNaN(extfib2) then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
def extfib3 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1.618 else extfib3[1];
plot extfib1618 = if showFibExtLines and currentPoints != 0 and upmove and !IsNaN(extfib3) then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
def extfib4 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 2.618 else extfib4[1];
plot extfib2618 = if showFibExtLines and currentPoints != 0 and upmove and !IsNaN(extfib4) then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
def extfib1_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1 else extfib1_[1];
plot extfib100_ = if showFibExtLines and currentPoints != 0 and dnmove and !IsNaN(extfib1_) then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
def extfib2_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 0.618 else extfib2_[1];
plot extfib618_ = if showFibExtLines and currentPoints != 0 and dnmove and !IsNaN(extfib2_) then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
def extfib3_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1.618 else extfib3_[1];
plot extfib1618_ = if showFibExtLines and currentPoints != 0 and dnmove and !IsNaN(extfib3_) then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
def extfib4_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 2.618 else extfib4_[1];
plot extfib2618_ = if showFibExtLines and currentPoints != 0 and dnmove and !IsNaN(extfib4_) then extfib4_[1] else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);

AddChartBubble(showFibExtLines and !IsNaN(extfib1[7]) and IsNaN(extfib1[6]), extfib1[8], "100%", Color.RED, no);
AddChartBubble(showFibExtLines and !IsNaN(extfib2[7]) and IsNaN(extfib2[6]), extfib2[8], "61.8%", Color.RED, no);
AddChartBubble(showFibExtLines and !IsNaN(extfib3[7]) and IsNaN(extfib3[6]), extfib3[8], "161.8%", Color.RED, no);
AddChartBubble(showFibExtLines and !IsNaN(extfib4[7]) and IsNaN(extfib4[6]), extfib4[8], "261.8%", Color.RED, no);
AddChartBubble(showFibExtLines and !IsNaN(extfib1_[7]) and IsNaN(extfib1_[6]), extfib1_[8], "100%", Color.GREEN, yes);
AddChartBubble(showFibExtLines and !IsNaN(extfib2[7]) and IsNaN(extfib2_[6]), extfib2_[8], "61.8%", Color.GREEN, yes);
AddChartBubble(showFibExtLines and !IsNaN(extfib3_[7]) and IsNaN(extfib3_[6]), extfib3_[8], "161.8%", Color.GREEN, yes);
AddChartBubble(showFibExtLines and !IsNaN(extfib4_[7]) and IsNaN(extfib4_[6]), extfib4_[8], "261.8%", Color.GREEN, yes);
#addlabel(yes,concat("Prior High: ", (if priorzz1>priorzz2 then priorzz1 else priorzz2))+concat(" Prior Low : ", (if priorzz1<priorzz2 then priorzz1 else priorzz2))+concat(" 2 Highs Ago: ", (if priorzz3>priorzz4 then priorzz3 else priorzz4))+concat(" 2 Lows Ago: ", (if priorzz3<priorzz4 then priorzz3 else priorzz4))+concat(" 3 Highs Ago: ", (if priorzz5>priorzz6 then priorzz5 else priorzz6))+concat(" 3 Lows Ago: ", (if priorzz5<priorzz6 then priorzz5 else priorzz6)));

#Horizontal Lines Added
def zzhigh = if zzSave == priceH then low else zzhigh[1];
plot zzupline = if showhorizontal == yes then zzhigh else Double.NaN;
zzupline.SetPaintingStrategy(PaintingStrategy.POINTS);
zzupline.SetDefaultColor(color = Color.RED);
zzupline.SetLineWeight(1);

def zzlow = if zzSave == priceL then high else zzlow[1];
plot zzlowline = if showhorizontal == yes then zzlow else Double.NaN;
zzlowline.SetPaintingStrategy(PaintingStrategy.POINTS);
zzlowline.SetDefaultColor(color = Color.GREEN);
zzlowline.SetLineWeight(1);

#Higher/Lower/Equal High, Higher/Lower/Equal Low
def xxhigh = if zzSave == priceH  then  high else xxhigh[1];
def chghigh = high - xxhigh[1];
def xxlow = if zzSave == priceL then low else xxlow[1];
def chglow = low - xxlow[1];

AddChartBubble(showBubbleshhll and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , if isUp and chghigh > 0 then "HH" else if isUp and chghigh < 0 then "LH" else if isUp then "EH" else if !isUp and chglow > 0 then "HL" else if !isUp and chglow < 0 then "LL" else "EL", if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);

#Price at High/Low
AddChartBubble(showBubblesprice and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , (if barNumber == barCount and currentPoints < 0 then "$" + priceH else if barNumber == barCount and currentPoints > 0 then "$" + priceL else "$" + currentPriceLevel)  , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);

#Price Change between zigzags
AddChartBubble(showBubbleschange and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , "$" + chg , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);

#Bar Count between zigzags
#Bar Count
rec zzcount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzcount[1] + 1 else 0;
def zzcounthilo   =  if zzcounthilo[1] == 0 and (zzSave == priceH or zzSave == priceL) then 1 else if zzSave == priceH or zzSave == priceL then zzcounthilo[1] + 1 else zzcounthilo[1];
def zzhilo = if zzSave == priceH or zzSave == priceL then zzcounthilo else zzcounthilo + 1;

def zzcounthigh = if zzSave == priceH then zzcount[1] else Double.NaN;
def zzcountlow =  if zzSave == priceL then zzcount[1] else Double.NaN;

AddChartBubble(showBubblesbarcount and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , if zzSave == priceH then zzcounthigh else zzcountlow, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, if isUp then yes else no );

#Supply Demand Areas
def cp = if currentPoints == 0 then 1 else if currentPoints != 0 then cp[1] + 1 else 0;
#def zzhigh = if zzSave == priceH  and (sum(close[-1]>close[-2],10)>=5 or cp[-30]>=30) then l else zzhigh[1];
def sdhigh = if zzSave == priceH then low else sdhigh[1];
plot sdupline = if showsupplydemand == no then Double.NaN else sdhigh[1];
sdupline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sdupline.SetDefaultColor(color = Color.RED);
sdupline.SetLineWeight(1);
#def zzhigh1 = if zzsave == priceH and (sum(close[-1]>close[-2],10)>=5 or cp[-30]>=30) then h else zzhigh1[1];
def sdhigh1 = if zzSave == priceH then high else sdhigh1[1];
plot sdupline1 = if showsupplydemand == no then Double.NaN else sdhigh1[1];
sdupline1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sdupline1.SetDefaultColor(color = Color.RED);
sdupline1.SetLineWeight(1);
AddCloud(if showsupplydemand then sdupline1 else Double.NaN, sdupline, Color.GRAY, Color.GRAY);

#def zzlow = if zzSave == priceL and (sum(close[-1]<close[-2],10)>=5 or or cp[-30]>=30) then h else zzlow[1];
def sdlow = if zzSave == priceL then high else sdlow[1];
plot sdlowline = if showsupplydemand == no then Double.NaN else sdlow[1];
sdlowline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sdlowline.SetDefaultColor(color = Color.GREEN);
sdlowline.SetLineWeight(1);
#def zzlow1 = if zzSave == priceL and (sum(close[-1]<close[-2],10)>=5 or or cp[-30]>=30) then l else zzlow1[1];
def sdlow1 = if zzSave == priceL then low else sdlow1[1];
plot sdlowline1 = if showsupplydemand == no then Double.NaN else sdlow1[1];
sdlowline1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sdlowline1.SetDefaultColor(color = Color.GREEN);
sdlowline1.SetLineWeight(1);
AddCloud(if showsupplydemand then sdlowline1 else Double.NaN, sdlowline, Color.GRAY, Color.GRAY);

#Fibs
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def zzfibh    = if zzSave == priceH and AbsValue(zzSave - zzSave[1]) > close * fibskipit * .01 then high  else zzfibh[1];
def zzfibl    = if zzSave == priceL and AbsValue(zzSave - zzSave[1]) > close * fibskipit * .01 then low  else zzfibl[1];
def range = zzfibh - zzfibl;
plot fibH = if showFibLines == no then Double.NaN else zzfibh;
plot fibL = if showFibLines == no then Double.NaN else zzfibl;
plot fibM = if showFibLines == no then Double.NaN else zzfibl + range * fibMlevel;
plot fib1 = if showFibLines == no then Double.NaN else zzfibl + range * fib1level;
plot fib2 = if showFibLines == no then Double.NaN else zzfibl + range * fib2level;
plot fib3 = if showFibLines == no then Double.NaN else zzfibl + range * fib3level;
plot fib4 = if showFibLines == no then Double.NaN else zzfibl + range * fib4level;
fibH.SetPaintingStrategy(PaintingStrategy.DASHES);
fibL.SetPaintingStrategy(PaintingStrategy.DASHES);
fibH.SetLineWeight(2);
fibL.SetLineWeight(2);
fibM.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibH.SetDefaultColor(Color.GREEN);
fibL.SetDefaultColor(Color.RED);
fibM.SetDefaultColor(Color.WHITE);
fib1.SetDefaultColor(Color.CYAN);
fib2.SetDefaultColor(Color.YELLOW);
fib3.SetDefaultColor(Color.YELLOW);
fib4.SetDefaultColor(Color.CYAN);

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - zzfibl) / (range))), if close > zzfibl then Color.GREEN else if zzfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , if isUp then AsPercent((high - zzfibl) / (range)) else AsPercent((low - zzfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);

#Wave C - This is still in development
def wave    = if chghigh < 0 and isUp or chglow > 0 and !isUp then 2 else 0;

AddChartBubble(showBubblewaveC and !IsNaN("ZZ$") and barNumber != 1 and wave == 2, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , Concat("Wave C", ""), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);

#Price Color
AssignPriceColor(if pricecolor then if !isConf then "ZZ$".Color("Undefined") else if isUp then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend") else Color.CURRENT);
plot Data = if pricecolor and !isConf then if open > close then low else high else Double.NaN;
Data.SetPaintingStrategy(PaintingStrategy.POINTS);
Data.AssignValueColor(if open > close then Color.RED else Color.GREEN);
Data.SetLineWeight(4);

#Volume at Reversals
def vol = if BarNumber() == 0 then 0 else volume + vol[1];
def vol1 = if BarNumber() == 1 then volume else vol1[1];
def xxvol = if zzSave == priceH or zzSave == priceL then TotalSum(volume) else xxvol[1];
def chgvol =  if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
plot cvol = chgvol;
cvol.AssignValueColor(if barCount == barNumber  or !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
cvol.SetHiding(showVolumeWave == no);
rec zzvol = if zzhilo[1] != zzhilo then 0 else zzvol[1] + volume;
plot zzvolupdn = if showVolumeWave then zzvol else Double.NaN;
zzvolupdn.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
zzvolupdn.AssignValueColor( if barCount == barNumber  or !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
plot zzt = if showVolumeWave then if zzSave == priceH or zzSave == priceL then chgvol else Double.NaN else Double.NaN;
zzt.EnableApproximation();
zzt.AssignValueColor( if barCount == barNumber  or !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
zzt.SetLineWeight(2);

AddChartBubble(showVolumeWave and !IsNaN("ZZ$") and barNumber != 1, chgvol , chgvol, if isUp then Color.GREEN else Color.RED, yes);

AddChartBubble(showVolumeWave and !IsNaN("ZZ$") and barNumber != 1, chgvol  , if zzSave == priceH then zzcounthigh else zzcountlow, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, yes );

AddChartBubble(showBubblesVolume and !IsNaN("ZZ$") and barNumber != 1, if isUp then priceH * (1 + bubbleoffset)  else priceL * (1 - bubbleoffset), chgvol, if isUp then Color.GREEN else Color.RED, if isUp then yes else no );

#Combined Bubbles
AddChartBubble(showcombinedbubble and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , Concat("", if isUp and chghigh > 0 then "HH" else if isUp and chghigh < 0 then "LH" else if isUp then "EH" else if !isUp and chglow > 0 then "HL" else if !isUp and chglow < 0 then "LL" else "EL") + "\n" + Concat("", if barNumber == barCount and currentPoints < 0 then "$" + priceH else if barNumber == barCount and currentPoints > 0 then "$" + priceL else "$" + currentPriceLevel) + "\n$" + chg + "\n" + Concat("", if chgvol != 0 or IsNaN(chgvol) then if isUp and chghigh > 0 then chgvol else if isUp and chghigh < 0 then chgvol else if isUp then chgvol else if !isUp and chglow > 0 then chgvol else if !isUp and chglow < 0 then chgvol else chgvol else Double.NaN) + "\n" + Concat("", if zzSave == priceH then zzcounthigh else zzcountlow) + "\n" + if isUp then AsPercent((high - zzfibl) / (range)) else AsPercent((low - zzfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, if isUp then yes else no );

AddChartBubble(showcombinedbubble2 and !IsNaN("ZZ$") and barNumber != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , "$" + chg + "\n" + Concat("", if barNumber == barCount and currentPoints < 0 then "$" + priceH else if barNumber == barCount and currentPoints > 0 then "$" + priceL else "$" + currentPriceLevel) , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, if isUp then yes else no );

#Showlabel for Confirmed/Unconfirmed Status of Current Zigzag
AddLabel(showconfirmedLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));

#Arrows
def zzL = if !IsNaN("ZZ$") and state == state.downtrend then priceL else GetValue(zzL, 1);
def zzH = if !IsNaN("ZZ$") and state == state.uptrend then priceH else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] then 1 else if zzH != zzH[1] then -1 else dir[1], 0);
def signal = CompoundValue(1,
    if dir > 0 and low > zzL then
        if signal[1] <= 0 then 1 else signal[1]
    else if dir < 0 and high < zzH then
        if signal[1] >= 0 then -1 else signal[1]
    else signal[1]
, 0);
plot U1 = showArrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(5);

plot isconfdn = if showArrows and !isUp and isconfreal then high + .05 else Double.NaN;
isconfdn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
isconfdn.SetLineWeight(5);
isconfdn.SetDefaultColor(Color.WHITE);

plot isconfup = if showArrows and isUp and isconfreal then low - .05 else Double.NaN;
isconfup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
isconfup.SetLineWeight(5);
isconfup.SetDefaultColor(Color.WHITE);

plot D1 = showArrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(5);

#Alerts
def EH_EL = if isUp and chghigh > 0 then 1 else if isUp and chghigh < 0 then 1 else if isUp then 2 else if !isUp and chglow > 0 then 1 else if !isUp and chglow < 0 then 1 else 3;
Alert(useAlerts and EH_EL == 2, "Even High", Alert.BAR, Sound.Ding);
Alert(useAlerts and EH_EL == 3, "Even Low", Alert.BAR, Sound.Ding);
Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(useAlerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);
Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);

#Additional Zigzag from TOS zigzaghighlow version using different ATR setting
input zzotherpriceh   = high;
input zzotherpricel   = low;
input zzotherperrev   = 0.2;
input zzotherabsrev   = 0.3;
input zzotheratrrev   = 5.0;
input zzotheratrlen   = 5;
input showotherbubble = no;
plot zzother = reference ZigZagHighLow(zzotherpriceh, zzotherpricel,  zzotherperrev, zzotherabsrev, "atr length" = zzotheratrlen, "atr reversal" = zzotheratrrev).ZZ;
zzother.EnableApproximation();
zzother.SetDefaultColor(Color.CYAN);
zzother.SetLineWeight(3);
def zzoth = if !IsNaN(zzother) then zzother else zzoth[1];
def chgzzoth = AbsValue(zzoth[1] - zzoth);
AddChartBubble(showotherbubble and !IsNaN(zzother), if zzother == high then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , "$" + zzother + "\n$" + chgzzoth , Color.CYAN, if zzother == high then yes else no);
## END CODE
 
H

horserider

Active member
Warehouse
@Simteaz Add two studies to the upper chart. Go to edit studies. Drag one of them to a lower panel. Then in the settings of the lower panel study change the "Showvolumewave+ from no to yes.
 
S

Simteaz

New member
VIP
it worked, thanks but this is the view on lower and higher time. Looks very off and I cant insert pic here
 

Top