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

Repaints
Thank you for sharing. I copied the code into TOS and there's an error that shows up.

The part of the code that reads:

Code:
AssignPriceColor(if PriceColor and gamma1
#crosses below
<
.382 then Color.WHITE else if PriceColor and gamma1
#crosses above
.618 then Color.CYAN else Color.CURRENT);

Is highlighted in RED in ThinkScript Editor so I think its reading it as an error. Is there a solution?
Below it reads: "Invalid statement: AssignPriceColor at 425:1"

Would it be easier to just share a chart with the Study embedded?
hint: there is something missing in the if-then.
look at the addlabel() just before the AssignPriceColor().
they have similar if-thens , that are defining colors.
 
Here is a scan version, that can be optimized, it's just simple removing all code except the one related with the ArrowUp & ArrowDown signal, which for this indicator is the entry Bull or Bear trades.

Ruby:
#def na = Double.NaN;
script R {
    input gamma              = .2;
    input usecandletype      = {candle_hybrid, default candle};
    input usehigheraggperiod = {default "Current", "Higher"};
    input outputformat       = {default Rounded, "Not Rounded"};
    ;#Hint outputformat: 'Not Rounded' is used for notes, bonds (eg: 109'110), forex, etc type format.
    input atrlength          = 21;
    input agg                = AggregationPeriod.TWO_MIN;
    input overbought         = .8;
    input oversold           = .2;
    def o;
    def h;
    def l;
    def c;
    def CU1;
    def CU2;
    def CU;
    def CD1;
    def CD2;
    def CD;
    def L0;
    def L1;
    def L2;
    def L3;
    plot RSI;
    plot OS;
    plot OB;
    def error = usehigheraggperiod == usehigheraggperiod."Higher" and GetAggregationPeriod() > agg;
    switch (usehigheraggperiod) {
    case Current:
        if usecandletype == usecandletype.candle_hybrid {
            o = (open + close[1]) / 2;
            h = Max(high, close[1]);
            l = Min(low, close[1]);
            c = (o + h + l + close) / 4;
        } else {
            o = open;
            h = high;
            l = low;
            c = close;
        }
    case Higher:
        if error {
            o = Double.NaN;
            h = Double.NaN;
            l = Double.NaN;
            c = Double.NaN;
        } else {
            if usecandletype == usecandletype.candle_hybrid {
                o = (open(period = agg)     + close(period = agg)[1]) / 2;
                h = Max(high(period = agg)  , close(period = agg)[1]);
                l = Min(low(period = agg)   , close(period = agg)[1]);
                c = ((open(period = agg)    + close(period = agg)[1]) / 2
            + Max(high(period = agg), close(period = agg)[1])
            + Min(low(period = agg) , close(period = agg)[1])
            + close(period = agg)) / 4;
            } else {
                o = open(period = agg);
                h = high(period = agg);
                l = low(period = agg);
                c = close(period = agg);
            }
        }
}
    L0 = (1 – gamma) * c + gamma * L0[1];
    L1 = -gamma * L0 + L0[1] + gamma * L1[1];
    L2 = -gamma * L1 + L1[1] + gamma * L2[1];
    L3 = -gamma * L2 + L2[1] + gamma * L3[1];
    if L0 >= L1
    then {
        CU1 = L0 - L1;
        CD1 = 0;
    } else {
        CD1 = L1 - L0;
        CU1 = 0;
    }
    if L1 >= L2
    then {
        CU2 = CU1 + L1 - L2;
        CD2 = CD1;
    } else {
        CD2 = CD1 + L2 - L1;
        CU2 = CU1;
    }
    if L2 >= L3
    then {
        CU = CU2 + L2 - L3;
        CD = CD2;
    } else {
        CU = CU2;
        CD = CD2 + L3 - L2;
    }


    RSI = if IsNaN(close) then Double.NaN
      else if CU + CD <> 0
      then    CU / (CU + CD) else 0;
    OS  = if IsNaN(close)
      then Double.NaN else oversold;
    OB  = if IsNaN(close)
      then Double.NaN
      else overbought;
    def mid = if IsNaN(close) then Double.NaN else 0.5;
    def lineh = 1.2;
    def linel = -.2;
   
# End Code Basic RSI Laguerre - Author: Mobius


}


def Up = if R() crosses above R().OS then 1 else 0;
def u = if R() crosses above R().OB then 1 else 0;


def Dn = if R() crosses below R().OB then 1 else 0;
def d = if R() crosses below R().OS then 1 else 0;


def Green = if Up
#or u
then low else 0;
def Red = if Dn
#or d
then high else 0;


input showArrows = yes;
plot ArrUp = if showArrows and Green then low else 0;
ArrUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrUp.SetDefaultColor(Color.GREEN);


plot ArrDn = if showArrows and Red then high else 0;
ArrDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrDn.SetDefaultColor(Color.RED);


9c6OVft.png
 
Last edited by a moderator:
@Zep This is all the code needed to show the arrows. So it may be possible if you look into what plots those arrows instead of just saying it is not allowed due to complexity. I just hacked away quickly and am not sure this will scan but you can try it. As was said above scan for U1 and D1.
Ruby:
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;
input showArrows = no;

#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);

#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 D1 = showArrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(5);
 
Last edited by a moderator:
@Zep This is all the code needed to show the arrows. So it may be possible if you look into what plots those arrows instead of just saying it is not allowed due to complexity. I just hacked away quickly and am not sure this will scan but you can try it. As was said above scan for U1 and D1.
...
tested and working with U1 or D1 condition set to "> 0 within X bars". Need to fine tune X and aggregation time to your needs. Note you also have to set "show arrows" to true.
 
Last edited:
Hi Ben
Thank you for you harmonic wave script
I want to ask if you have scan for the script
ABCD or strong Henry
Please let me know
The harmonic with fibonacci are amazing ✌🏼✌🏼
 
How would the logic tree work if you wanted the fractals to count from the first high from the lowest low, to be labeled 2, then the lower fractal 3, higher, 4, etc until the first lower high creates a zigzag?

I’m trying to figure out ways to just have 1,2,3,etc to save a ton of labels. 3 being the one I really wanna see, and odd numbers, so I know where the strength in waves likely are to occur without a ton of counting and head scratching.

I’m not sure the best way to post a picture but if someone has any ideas I’ll do so. I do it manually so far.
 
Last edited:
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
the AddVerticalLine line always draw "Buy" line even if it is supposed to be " sell", can it be revised to draw vertical lines at both Buy and Sell? vertical lines

The addvertical line only draw "Buy" line even if it is supposed to be sell verical line
Thanks
 
Last edited by a moderator:
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.

l4TJPs6.png


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

https://tos.mx/DuAPJc

Video Tutorial

Hi Ben is there scan for this script thank you
 
Does anyone know any reference material to what each definition is?

I’d love to find a nenstar, that seems to be the one that rides the large waves.
 
Has anyone purchased and tested this code from the FunWithThinkScript site? Basically is it worth the rent payment price tag? I am asking becase I pucrchaed a code for about $150 couple years ago and it was a bit over advertised and the Harmonic Patterns; "Butterfly" specifically is a bit tough to code on my own. Can anyone vouch for this code? And were you able to see it working on your TOS platform? I already checked the available Free Harmonic patterns on this site but I am only intrested in Bullish setups and find it difficult to turn off or reverse engineer all the other setups from the given script.
I found it digging deep on the internet for a fraction of the price. The only difference is the scan doesn't look as good on mine. It just prints a 0.0 or 1.0 on each time frame on whether there's a pattern or not. It prints the patterns in real time which is cool but just like any TA indicators there is no god indicator that's going to make you win all your battles.
 
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.

l4TJPs6.png


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

https://tos.mx/DuAPJc

Video Tutorial

What are main differences between your homaronic patterns indicator and Multi Level ZigZag Harmonic Patterns?
https://www.tradingview.com/script/aRVrNdOL-Multi-Level-ZigZag-Harmonic-Patterns/
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
484 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top