Here are some of the indicators I use every day

Status
Not open for further replies.
Hello, I've been trying to understand the difference between using a 5 period and 13 period with Wolf Wave but haven't found an answer. Does anyone know? Thanks so much.
Those numbers represent the lookback window used... Shorter responds more quickly and may give more false signals... Longer responds slower and is less apt to give false signals, but you could potentially miss early moves... Those settings should be adjusted for your personal preference and trading style...
 

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

Just put this chart together this morning I'll try it out today. I am enjoying the simplicity of the Renko charts and the clean charts. Here I am using the .20 setting for the higher profit margins in trading the waves. What makes this work for me is a script called Basic Market Structure ver 3.01
funwiththinkscript.com. This is just another tool I am not advertising anything here and believe me I am not in the habit of buying script but this has paid for itself many times over. So this does mark the minor/major waves within any given time frame and a few other things too and it works on all time frames and candle patterns. Profits are at the end of each wave line the chart is set to show the minor waves. In proven theory, this works for me.

So I played this apple short yesterday.

 
Last edited:
I don't trade the /es but thought I would throw this up because people need to know.

qJdQ4oA.png
 
@Shooters_Gotta_Shoot @samoya Found these harmonic pattern scripts the other day. Someone may find them helpful. Haven't looked at it while the market is open but it seems they don't paint in real time, meaning there is no "early warning sign" and the drawing just appears making them hard to catch. Wasn't able to make a scanner for them, too complex, but maybe one of the smart people on here could.

Here is a chart look: https://tos.mx/I3RaLkB

Gartley pattern

Code:
# +--------------------------------------------------+

script InRange {
    input start = 0;
    input end = 0;
    input lower = 0;
    input upper = 0;

    def f0 = 0.264;
    def f1 = 0.382;
    def f2 = 0.500;
    def f3 = 0.618;
    def f4 = 0.707;
    def f5 = 0.786;
    def f6 = 0.886;
    def f7 = 1.000;

    def range = end - start;
    def p1 = if lower == f6 then f5 else
             if lower == f5 then f4 else
             if lower == f4 then f3 else
             if lower == f3 then f2 else
             if lower == f2 then f1 else
             f0;
    def p2 = if upper == f1 then f2 else
             if upper == f2 then f3 else
             if upper == f3 then f4 else
             if upper == f4 then f5 else
             if upper == f5 then f6 else
             f7;
    def n1 = end - range * p1;
    def n2 = end - range * p2;
    def upperRange = Max(n1, n2);
    def lowerRange = Min(n1, n2);

    plot inRange = if range > 0 then low < upperRange and low > lowerRange
                   else high < upperRange and high > lowerRange;
}

script PRZ {
    input x = 0;
    input a = 0;
    input b = 0;
    input c = 0;
    input abcd = 0;
    input xd1 = 0;
    input xd2 = 0;
    input cd1 = 0;
    input cd2 = 0;

    def XArng = (a - x);
    def ABrng = (a - b);
    def BCrng = (c - b);
    def Cr = AbsValue(BCrng) / AbsValue(ABrng);
    def Cret = if Cr >= 0.836 then 0.886 else
               if Cr >= 0.747 then 0.786 else
               if Cr >= 0.663 then 0.707 else
               if Cr >= 0.559 then 0.618 else
               if Cr >= 0.441 then 0.500 else
               0.382;
    def Cex = if 1 / Cret < cd1 then cd1 else if 1 / Cret > cd2 then cd2 else 1 / Cret;
    plot prz1 = c - (ABrng * abcd);
    plot prz2 = c - (BCrng * Cex);
    plot prz3 = a - (XArng * xd1);
    plot prz4 = a - (XArng * xd2);
    plot przMax = Max(Max(prz1, prz2), Max(prz3, prz4));
    plot przMin = Min(Min(prz1, prz2), Min(prz3, prz4));

}

input waveLength = 13;
input labelPoints = yes;

def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = Min(waveLength - 1, lastBar - BarNumber());

def pHigh = high == Highest(high, waveLength) and high == GetValue(Highest(high, waveLength), -offset);
def pLow = low == Lowest(low, waveLength) and low == GetValue(Lowest(low, waveLength), -offset);

def cph = if pHigh[1] then 1 else cph[1] + 1;
def cpl = if pLow[1] then 1 else cpl[1] + 1;

def wHigh = ((pHigh and !pLow) or (pHigh and pLow and cpl < cph)) and cph >= waveLength;
def wLow = ((pLow and !pHigh) or (pLow and pHigh and cph < cpl)) and cpl >= waveLength;

def spHigh = if wLow[1] then high else if high > spHigh[1] then high else spHigh[1];
def bHigh = if wHigh then 0 else if wLow[1] then BarNumber() else if high >= spHigh[1] then BarNumber() else bHigh[1];
def spLow = if wHigh[1] then low else if low < spLow[1] then low else spLow[1];
def bLow = if wLow then 0 else if wHigh[1] then BarNumber() else if low <= spLow[1] then BarNumber() else bLow[1];

def cpwh = if wHigh[1] then 1 else cpwh[1] + 1;
def cpwl = if wLow[1] then 1 else cpwl[1] + 1;
def cnwh = fold i = 1 to lastBar with a = Double.NaN while IsNaN(a) do if GetValue(wHigh, -i) then i else Double.NaN;
def cnwl = fold j = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(wLow, -j) then j else Double.NaN;

def mwHigh = if !wHigh and (cpwl < cpwh) and BarNumber() == GetValue(bHigh[1], -cnwl) then 1 else Double.NaN;
def mwLow = if !wLow and (cpwh < cpwl) and BarNumber() == GetValue(bLow[1], -cnwh) then 1 else Double.NaN;

def peak = if IsNaN(close) then 0 else wHigh or !IsNaN(mwHigh);
def valley = if IsNaN(close) then 0 else wLow or !IsNaN(mwLow);

def lastPeakBar = HighestAll(if peak then BarNumber() else 0);
def lastPeak = BarNumber() == lastPeakBar;
def lastValleyBar = HighestAll(if valley then BarNumber() else 0);
def lastValley = BarNumber() == lastValleyBar;

def cpp = if peak[1] then 1 else cpp[1] + 1;
def cpv = if valley[1] then 1 else cpv[1] + 1;

def prevHigh = GetValue(high, cpp);
def prevLow = GetValue(low, cpv);
def prevHigh2 = GetValue(prevHigh, cpp);
def prevLow2 = GetValue(prevLow, cpv);

def cnp = if BarNumber() >= lastPeakBar then 0 else fold k = 1 to lastBar with c = 0 while c == 0 do if GetValue(peak, -k) then k else 0;
def cnp2 = cnp + GetValue(cnp, -cnp);
def cnv = if BarNumber() >= lastValleyBar then 0 else fold l = 1 to lastBar with d = 0 while d == 0 do if GetValue(valley, -l) then l else 0;
def cnv2 = cnv + GetValue(cnv, -cnv);

def nextHigh = if BarNumber() >= lastPeakBar then Double.NaN else GetValue(high, -cnp);
def nextLow = if BarNumber() >= lastValleyBar then Double.NaN else GetValue(low, -cnv);
def nextHigh2 = if IsNaN(GetValue(nextHigh, -cnp)) then nextHigh2[1] else GetValue(nextHigh, -cnp);
def nextLow2 = if IsNaN(GetValue(nextLow, -cnv)) then nextLow2[1] else GetValue(nextLow, -cnv);

def hf0 = 0.618;
def hf1 = 0.618;
def hf2 = 0.382;
def hf3 = 0.886;
def hf4 = 1.000;
def hf5 = 0.786;
def hf6 = 0.786;
def hf7 = 1.129;
def hf8 = 1.618;

input FudgeFactor = 0.8;
def FF = ATR()[1] * FudgeFactor;

def Lprz = waveLength * 2;
def blg1 = valley and inrange(prevLow, prevHigh, hf0, hf1);
def blg2 = peak and GetValue(blg1, cpv) and inrange(prevHigh, prevLow, hf2, hf3);
def blg3 = valley and GetValue(blg2, cpp);

def cv1 = if blg2 then 0 else cv1[1] + 1;
def blgz1 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz1[1], Double.NaN);
def blgz2 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz2[1], Double.NaN);

def blg4 = (low <= prevLow + ATR() * 2 and blg3 and !cnp and high >= blgz2 - FF) or (low <= prevLow and blg3 and cnp and (high >= (blgz2 - FF) and low <= (blgz1 + FF)));
def blg5 = if IsNaN(blg4) then 0 else blg4;
def blgX = valley and GetValue(blg5, -cnv2) and cnv2 > cnv;
def blgA = peak and GetValue(blgX, cpv);
def blgB = valley and GetValue(blgA, cpp);
def blgC = peak and GetValue(blgB, cpv);
def blgD = valley and GetValue(blgC, cpp);

def aBullWave = CompoundValue(1, if blgX and GetValue(blgD, -cnv2) then 1 else if blgD[1] and !blgX[1] then 0 else aBullWave[1], 0);

DefineGlobalColor("Bullish Labels", Color.LIGHT_GREEN);

AddChartBubble(blgX and labelPoints, low, "X", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgA and labelPoints, high, "A", GlobalColor("Bullish Labels"));
AddChartBubble(blgB and labelPoints, low, "B", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgC and labelPoints, high, "C", GlobalColor("Bullish Labels"));
AddChartBubble(blgD and labelPoints, low, "D", GlobalColor("Bullish Labels"), 0);

def abl = CompoundValue(1, if aBullWave and !aBullWave[1] then 0 else if aBullWave and blgC then 1 else abl[1], 0);
def blgPRZ1 = if IsNaN(close) then blgPRZ1[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz1 else Double.NaN;
def blgPRZ2 = if IsNaN(close) then blgPRZ2[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz2 else Double.NaN;

plot PRZlmax = blgPRZ1;
     PRZlmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZlmin = blgPRZ2;
     PRZlmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bullish PRZ", CreateColor(163, 221, 255));
AddCloud(PRZlmax, PRZlmin, GlobalColor("Bullish PRZ"));

def brg1 = peak and inrange(prevHigh, prevLow, hf0, hf1);
def brg2 = valley and GetValue(brg1, cpp) and inrange(prevLow, prevHigh, hf2, hf3);
def brg3 = peak and GetValue(brg2, cpv);

def cr1 = if brg2 then 0 else cr1[1] + 1;
def brgz1 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz1[1], Double.NaN);
def brgz2 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz2[1], Double.NaN);

def brg4 = (high >= prevHigh - ATR() * 2 and brg3 and !cnv and low <= brgz1 + FF) or (high >= prevHigh and brg3 and cnv and (low <= (brgz1 + FF) and high >= (brgz2 - FF)));
def brg5 = if IsNaN(brg4) then 0 else brg4;
def brgX = peak and GetValue(brg5, -cnp2) and cnp2 > cnp;
def brgA = valley and GetValue(brgX, cpp);
def brgB = peak and GetValue(brgA, cpv);
def brgC = valley and GetValue(brgB, cpp);
def brgD = peak and GetValue(brgC, cpv);

def aBearWave = if brgX and GetValue(brgD, -cnp2) then 1 else if brgD[1] and !brgX[1] then 0 else aBearWave[1];

DefineGlobalColor("Bearish Labels", Color.PINK);

AddChartBubble(brgX and labelPoints, high, "X", GlobalColor("Bearish Labels"));
AddChartBubble(brgA and labelPoints, low, "A", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgB and labelPoints, high, "B", GlobalColor("Bearish Labels"));
AddChartBubble(brgC and labelPoints, low, "C", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgD and labelPoints, high, "D", GlobalColor("Bearish Labels"));

def abr = CompoundValue(1, if aBearWave and !aBearWave[1] then 0 else if aBearWave and brgC then 1 else abr[1], 0);
def brgPRZ1 = if IsNaN(close) then brgPRZ1[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz1 else Double.NaN;
def brgPRZ2 = if IsNaN(close) then brgPRZ2[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz2 else Double.NaN;

plot PRZrmax = brgPRZ1;
     PRZrmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZrmin = brgPRZ2;
     PRZrmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bearish PRZ", CreateColor(226, 163, 255));
AddCloud(PRZrmax, PRZrmin, GlobalColor("Bearish PRZ"));

def mWave = if BarNumber() < lastPeakBar and valley then ((nextHigh - low) / cnp) else if BarNumber() < lastValleyBar and peak then ((nextLow - high) / cnv) else mWave[1];
def waveLine = if valley then low else if peak then high else waveLine[1] + mWave;

plot bullWave = if aBullWave then waveLine else Double.NaN;
     bullWave.SetDefaultColor(Color.WHITE);
     bullWave.SetLineWeight(2);
plot bearWave = if aBearWave then waveLine else Double.NaN;
     bearWave.SetDefaultColor(Color.WHITE);
     bearWave.SetLineWeight(2);

def mPeak = if BarNumber() < lastPeakBar and peak then ((nextHigh - high) / cnp) else mPeak[1];
def lPeak = if peak then high else lPeak[1] + mPeak;
def peakLine = if aBearWave then lPeak else Double.NaN;
AddCloud(peakLine, bearWave, Color.PINK);

def mValley = if BarNumber() < lastValleyBar and valley then ((nextLow - low) / cnv) else mValley[1];
def lvalley = if valley then low else lvalley[1] + mValley;
def valleyLine = if aBullWave then lvalley else Double.NaN;
AddCloud(bullWave, valleyLine, Color.LIGHT_GREEN);

#=============
input ShowTargetZones = No;

def brS = if IsNaN(nextHigh) then 0 else if nextHigh > high then 1 else 0;
def brT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.382 + high else brT1[1], Double.NaN);
def brT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.618 + high else brT2[1], Double.NaN);
def brT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.786 + high else brT3[1], Double.NaN);
def brT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.000 + high else brT4[1], Double.NaN);
def brT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.27 + high else brT5[1], Double.NaN);
def brT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.618 + high else brT6[1], Double.NaN);
plot bearT1 = if !ShowTargetZones then Double.NaN else brT1;
     bearT1.SetDefaultColor(Color.DARK_RED);
     bearT1.SetLineWeight(2);
plot bearT2 = if !ShowTargetZones then Double.NaN else brT2;
     bearT2.SetDefaultColor(Color.DARK_RED);
     bearT2.SetLineWeight(2);
plot bearT3 = if !ShowTargetZones then Double.NaN else brT3;
     bearT3.SetDefaultColor(Color.DARK_RED);
     bearT3.SetLineWeight(2);
plot bearT4 = if !ShowTargetZones then Double.NaN else brT4;
     bearT4.SetDefaultColor(Color.DARK_RED);
     bearT4.SetLineWeight(2);
plot bearT5 = if !ShowTargetZones then Double.NaN else brT5;
     bearT5.SetDefaultColor(Color.DARK_RED);
     bearT5.SetLineWeight(2);
plot bearT6 = if !ShowTargetZones then Double.NaN else brT6;
     bearT6.SetDefaultColor(Color.DARK_RED);
     bearT6.SetLineWeight(2);
AddCloud(bearT2, bearT3, Color.YELLOW);
AddCloud(bearT5, bearT6, Color.YELLOW);

def blS = if IsNaN(nextLow) then 0 else if nextLow < low then 1 else 0;
def blT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.382 + low else blT1[1], Double.NaN);
def blT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.618 + low else blT2[1], Double.NaN);
def blT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.786 + low else blT3[1], Double.NaN);
def blT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.000 + low else blT4[1], Double.NaN);
def blT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.27 + low else blT5[1], Double.NaN);
def blT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.618 + low else blT6[1], Double.NaN);
plot bullT1 = if !ShowTargetZones then Double.NaN else blT1;
     bullT1.SetDefaultColor(Color.DARK_GREEN);
     bullT1.SetLineWeight(2);
plot bullT2 = if !ShowTargetZones then Double.NaN else blT2;
     bullT2.SetDefaultColor(Color.DARK_GREEN);
     bullT2.SetLineWeight(2);
plot bullT3 = if !ShowTargetZones then Double.NaN else blT3;
     bullT3.SetDefaultColor(Color.DARK_GREEN);
     bullT3.SetLineWeight(2);
plot bullT4 = if !ShowTargetZones then Double.NaN else blT4;
     bullT4.SetDefaultColor(Color.DARK_GREEN);
     bullT4.SetLineWeight(2);
plot bullT5 = if !ShowTargetZones then Double.NaN else blT5;
     bullT5.SetDefaultColor(Color.DARK_GREEN);
     bullT5.SetLineWeight(2);
plot bullT6 = if !ShowTargetZones then Double.NaN else blT6;
     bullT6.SetDefaultColor(Color.DARK_GREEN);
     bullT6.SetLineWeight(2);
AddCloud(bullT3, bullT2, Color.YELLOW);
AddCloud(bullT6, bullT5, Color.YELLOW);


Bat Pattern

Code:
# +--------------------------------------------------+

script InRange {
    input start = 0;
    input end = 0;
    input lower = 0;
    input upper = 0;

    def f0 = 0.264;
    def f1 = 0.382;
    def f2 = 0.500;
    def f3 = 0.618;
    def f4 = 0.707;
    def f5 = 0.786;
    def f6 = 0.886;
    def f7 = 1.000;

    def range = end - start;
    def p1 = if lower == f6 then f5 else
             if lower == f5 then f4 else
             if lower == f4 then f3 else
             if lower == f3 then f2 else
             if lower == f2 then f1 else
             f0;
    def p2 = if upper == f1 then f2 else
             if upper == f2 then f3 else
             if upper == f3 then f4 else
             if upper == f4 then f5 else
             if upper == f5 then f6 else
             f7;
    def n1 = end - range * p1;
    def n2 = end - range * p2;
    def upperRange = Max(n1, n2);
    def lowerRange = Min(n1, n2);

    plot inRange = if range > 0 then low < upperRange and low > lowerRange
                   else high < upperRange and high > lowerRange;
}

script PRZ {
    input x = 0;
    input a = 0;
    input b = 0;
    input c = 0;
    input abcd = 0;
    input xd1 = 0;
    input xd2 = 0;
    input cd1 = 0;
    input cd2 = 0;

    def XArng = (a - x);
    def ABrng = (a - b);
    def BCrng = (c - b);
    def Cr = AbsValue(BCrng) / AbsValue(ABrng);
    def Cret = if Cr >= 0.836 then 0.886 else
               if Cr >= 0.747 then 0.786 else
               if Cr >= 0.663 then 0.707 else
               if Cr >= 0.559 then 0.618 else
               if Cr >= 0.441 then 0.500 else
               0.382;
    def Cex = if 1 / Cret < cd1 then cd1 else if 1 / Cret > cd2 then cd2 else 1 / Cret;
    plot prz1 = c - (ABrng * abcd);
    plot prz2 = c - (BCrng * Cex);
    plot prz3 = a - (XArng * xd1);
    plot prz4 = a - (XArng * xd2);
    plot przMax = Max(Max(prz1, prz2), Max(prz3, prz4));
    plot przMin = Min(Min(prz1, prz2), Min(prz3, prz4));

}

input waveLength = 13;
input labelPoints = yes;

def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = Min(waveLength - 1, lastBar - BarNumber());

def pHigh = high == Highest(high, waveLength) and high == GetValue(Highest(high, waveLength), -offset);
def pLow = low == Lowest(low, waveLength) and low == GetValue(Lowest(low, waveLength), -offset);

def cph = if pHigh[1] then 1 else cph[1] + 1;
def cpl = if pLow[1] then 1 else cpl[1] + 1;

def wHigh = ((pHigh and !pLow) or (pHigh and pLow and cpl < cph)) and cph >= waveLength;
def wLow = ((pLow and !pHigh) or (pLow and pHigh and cph < cpl)) and cpl >= waveLength;

def spHigh = if wLow[1] then high else if high > spHigh[1] then high else spHigh[1];
def bHigh = if wHigh then 0 else if wLow[1] then BarNumber() else if high >= spHigh[1] then BarNumber() else bHigh[1];
def spLow = if wHigh[1] then low else if low < spLow[1] then low else spLow[1];
def bLow = if wLow then 0 else if wHigh[1] then BarNumber() else if low <= spLow[1] then BarNumber() else bLow[1];

def cpwh = if wHigh[1] then 1 else cpwh[1] + 1;
def cpwl = if wLow[1] then 1 else cpwl[1] + 1;
def cnwh = fold i = 1 to lastBar with a = Double.NaN while IsNaN(a) do if GetValue(wHigh, -i) then i else Double.NaN;
def cnwl = fold j = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(wLow, -j) then j else Double.NaN;

def mwHigh = if !wHigh and (cpwl < cpwh) and BarNumber() == GetValue(bHigh[1], -cnwl) then 1 else Double.NaN;
def mwLow = if !wLow and (cpwh < cpwl) and BarNumber() == GetValue(bLow[1], -cnwh) then 1 else Double.NaN;

def peak = if IsNaN(close) then 0 else wHigh or !IsNaN(mwHigh);
def valley = if IsNaN(close) then 0 else wLow or !IsNaN(mwLow);

def lastPeakBar = HighestAll(if peak then BarNumber() else 0);
def lastPeak = BarNumber() == lastPeakBar;
def lastValleyBar = HighestAll(if valley then BarNumber() else 0);
def lastValley = BarNumber() == lastValleyBar;

def cpp = if peak[1] then 1 else cpp[1] + 1;
def cpv = if valley[1] then 1 else cpv[1] + 1;

def prevHigh = GetValue(high, cpp);
def prevLow = GetValue(low, cpv);
def prevHigh2 = GetValue(prevHigh, cpp);
def prevLow2 = GetValue(prevLow, cpv);

def cnp = if BarNumber() >= lastPeakBar then 0 else fold k = 1 to lastBar with c = 0 while c == 0 do if GetValue(peak, -k) then k else 0;
def cnp2 = cnp + GetValue(cnp, -cnp);
def cnv = if BarNumber() >= lastValleyBar then 0 else fold l = 1 to lastBar with d = 0 while d == 0 do if GetValue(valley, -l) then l else 0;
def cnv2 = cnv + GetValue(cnv, -cnv);

def nextHigh = if BarNumber() >= lastPeakBar then Double.NaN else GetValue(high, -cnp);
def nextLow = if BarNumber() >= lastValleyBar then Double.NaN else GetValue(low, -cnv);
def nextHigh2 = if IsNaN(GetValue(nextHigh, -cnp)) then nextHigh2[1] else GetValue(nextHigh, -cnp);
def nextLow2 = if IsNaN(GetValue(nextLow, -cnv)) then nextLow2[1] else GetValue(nextLow, -cnv);

def hf0 = 0.382;
def hf1 = 0.500;
def hf2 = 0.382;
def hf3 = 0.886;
def hf4 = 1.618;
def hf5 = 0.886;
def hf6 = 0.886;
def hf7 = 1.618;
def hf8 = 2.618;

input FudgeFactor = 0.8;
def FF = ATR()[1] * FudgeFactor;

def Lprz = waveLength * 2;
def blg1 = valley and inrange(prevLow, prevHigh, hf0, hf1);
def blg2 = peak and GetValue(blg1, cpv) and inrange(prevHigh, prevLow, hf2, hf3);
def blg3 = valley and GetValue(blg2, cpp);

def cv1 = if blg2 then 0 else cv1[1] + 1;
def blgz1 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz1[1], Double.NaN);
def blgz2 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz2[1], Double.NaN);

def blg4 = (low <= prevLow + ATR() * 2 and blg3 and !cnp and high >= blgz2 - FF) or (low <= prevLow and blg3 and cnp and (high >= (blgz2 - FF) and low <= (blgz1 + FF)));
def blg5 = if IsNaN(blg4) then 0 else blg4;
def blgX = valley and GetValue(blg5, -cnv2) and cnv2 > cnv;
def blgA = peak and GetValue(blgX, cpv);
def blgB = valley and GetValue(blgA, cpp);
def blgC = peak and GetValue(blgB, cpv);
def blgD = valley and GetValue(blgC, cpp);

def aBullWave = CompoundValue(1, if blgX and GetValue(blgD, -cnv2) then 1 else if blgD[1] and !blgX[1] then 0 else aBullWave[1], 0);

DefineGlobalColor("Bullish Labels", Color.LIGHT_GREEN);

AddChartBubble(blgX and labelPoints, low, "X", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgA and labelPoints, high, "A", GlobalColor("Bullish Labels"));
AddChartBubble(blgB and labelPoints, low, "B", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgC and labelPoints, high, "C", GlobalColor("Bullish Labels"));
AddChartBubble(blgD and labelPoints, low, "D", GlobalColor("Bullish Labels"), 0);

def abl = CompoundValue(1, if aBullWave and !aBullWave[1] then 0 else if aBullWave and blgC then 1 else abl[1], 0);
def blgPRZ1 = if IsNaN(close) then blgPRZ1[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz1 else Double.NaN;
def blgPRZ2 = if IsNaN(close) then blgPRZ2[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz2 else Double.NaN;

plot PRZlmax = blgPRZ1;
PRZlmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZlmin = blgPRZ2;
PRZlmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bullish PRZ", CreateColor(163, 221, 255));
AddCloud(PRZlmax, PRZlmin, GlobalColor("Bullish PRZ"));

def brg1 = peak and inrange(prevHigh, prevLow, hf0, hf1);
def brg2 = valley and GetValue(brg1, cpp) and inrange(prevLow, prevHigh, hf2, hf3);
def brg3 = peak and GetValue(brg2, cpv);

def cr1 = if brg2 then 0 else cr1[1] + 1;
def brgz1 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz1[1], Double.NaN);
def brgz2 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz2[1], Double.NaN);

def brg4 = (high >= prevHigh - ATR() * 2 and brg3 and !cnv and low <= brgz1 + FF) or (high >= prevHigh and brg3 and cnv and (low <= (brgz1 + FF) and high >= (brgz2 - FF)));
def brg5 = if IsNaN(brg4) then 0 else brg4;
def brgX = peak and GetValue(brg5, -cnp2) and cnp2 > cnp;
def brgA = valley and GetValue(brgX, cpp);
def brgB = peak and GetValue(brgA, cpv);
def brgC = valley and GetValue(brgB, cpp);
def brgD = peak and GetValue(brgC, cpv);

def aBearWave = if brgX and GetValue(brgD, -cnp2) then 1 else if brgD[1] and !brgX[1] then 0 else aBearWave[1];

DefineGlobalColor("Bearish Labels", Color.PINK);

AddChartBubble(brgX and labelPoints, high, "X", GlobalColor("Bearish Labels"));
AddChartBubble(brgA and labelPoints, low, "A", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgB and labelPoints, high, "B", GlobalColor("Bearish Labels"));
AddChartBubble(brgC and labelPoints, low, "C", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgD and labelPoints, high, "D", GlobalColor("Bearish Labels"));

def abr = CompoundValue(1, if aBearWave and !aBearWave[1] then 0 else if aBearWave and brgC then 1 else abr[1], 0);
def brgPRZ1 = if IsNaN(close) then brgPRZ1[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz1 else Double.NaN;
def brgPRZ2 = if IsNaN(close) then brgPRZ2[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz2 else Double.NaN;

plot PRZrmax = brgPRZ1;
PRZrmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZrmin = brgPRZ2;
PRZrmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bearish PRZ", CreateColor(226, 163, 255));
AddCloud(PRZrmax, PRZrmin, GlobalColor("Bearish PRZ"));

def mWave = if BarNumber() < lastPeakBar and valley then ((nextHigh - low) / cnp) else if BarNumber() < lastValleyBar and peak then ((nextLow - high) / cnv) else mWave[1];
def waveLine = if valley then low else if peak then high else waveLine[1] + mWave;

plot bullWave = if aBullWave then waveLine else Double.NaN;
bullWave.SetDefaultColor(Color.WHITE);
bullWave.SetLineWeight(2);
plot bearWave = if aBearWave then waveLine else Double.NaN;
bearWave.SetDefaultColor(Color.WHITE);
bearWave.SetLineWeight(2);

def mPeak = if BarNumber() < lastPeakBar and peak then ((nextHigh - high) / cnp) else mPeak[1];
def lPeak = if peak then high else lPeak[1] + mPeak;
def peakLine = if aBearWave then lPeak else Double.NaN;
AddCloud(peakLine, bearWave, Color.PINK);

def mValley = if BarNumber() < lastValleyBar and valley then ((nextLow - low) / cnv) else mValley[1];
def lvalley = if valley then low else lvalley[1] + mValley;
def valleyLine = if aBullWave then lvalley else Double.NaN;
AddCloud(bullWave, valleyLine, Color.LIGHT_GREEN);

#=============
input ShowTargetZones = No;

def brS = if IsNaN(nextHigh) then 0 else if nextHigh > high then 1 else 0;
def brT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.382 + high else brT1[1], Double.NaN);
def brT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.618 + high else brT2[1], Double.NaN);
def brT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.786 + high else brT3[1], Double.NaN);
def brT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.000 + high else brT4[1], Double.NaN);
def brT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.27 + high else brT5[1], Double.NaN);
def brT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.618 + high else brT6[1], Double.NaN);
plot bearT1 = if !ShowTargetZones then Double.NaN else brT1;
bearT1.SetDefaultColor(Color.DARK_RED);
bearT1.SetLineWeight(2);
plot bearT2 = if !ShowTargetZones then Double.NaN else brT2;
bearT2.SetDefaultColor(Color.DARK_RED);
bearT2.SetLineWeight(2);
plot bearT3 = if !ShowTargetZones then Double.NaN else brT3;
bearT3.SetDefaultColor(Color.DARK_RED);
bearT3.SetLineWeight(2);
plot bearT4 = if !ShowTargetZones then Double.NaN else brT4;
bearT4.SetDefaultColor(Color.DARK_RED);
bearT4.SetLineWeight(2);
plot bearT5 = if !ShowTargetZones then Double.NaN else brT5;
bearT5.SetDefaultColor(Color.DARK_RED);
bearT5.SetLineWeight(2);
plot bearT6 = if !ShowTargetZones then Double.NaN else brT6;
bearT6.SetDefaultColor(Color.DARK_RED);
bearT6.SetLineWeight(2);
AddCloud(bearT2, bearT3, Color.YELLOW);
AddCloud(bearT5, bearT6, Color.YELLOW);

def blS = if IsNaN(nextLow) then 0 else if nextLow < low then 1 else 0;
def blT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.382 + low else blT1[1], Double.NaN);
def blT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.618 + low else blT2[1], Double.NaN);
def blT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.786 + low else blT3[1], Double.NaN);
def blT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.000 + low else blT4[1], Double.NaN);
def blT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.27 + low else blT5[1], Double.NaN);
def blT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.618 + low else blT6[1], Double.NaN);
plot bullT1 = if !ShowTargetZones then Double.NaN else blT1;
bullT1.SetDefaultColor(Color.DARK_GREEN);
bullT1.SetLineWeight(2);
plot bullT2 = if !ShowTargetZones then Double.NaN else blT2;
bullT2.SetDefaultColor(Color.DARK_GREEN);
bullT2.SetLineWeight(2);
plot bullT3 = if !ShowTargetZones then Double.NaN else blT3;
bullT3.SetDefaultColor(Color.DARK_GREEN);
bullT3.SetLineWeight(2);
plot bullT4 = if !ShowTargetZones then Double.NaN else blT4;
bullT4.SetDefaultColor(Color.DARK_GREEN);
bullT4.SetLineWeight(2);
plot bullT5 = if !ShowTargetZones then Double.NaN else blT5;
bullT5.SetDefaultColor(Color.DARK_GREEN);
bullT5.SetLineWeight(2);
plot bullT6 = if !ShowTargetZones then Double.NaN else blT6;
bullT6.SetDefaultColor(Color.DARK_GREEN);
bullT6.SetLineWeight(2);
AddCloud(bullT3, bullT2, Color.YELLOW);
AddCloud(bullT6, bullT5, Color.YELLOW);

def signal= przrmax;
plot signal1= przrmax;

Butterfly pattern
Code:
# +--------------------------------------------------+

script InRange {
    input start = 0;
    input end = 0;
    input lower = 0;
    input upper = 0;

    def f0 = 0.264;
    def f1 = 0.382;
    def f2 = 0.500;
    def f3 = 0.618;
    def f4 = 0.707;
    def f5 = 0.786;
    def f6 = 0.886;
    def f7 = 1.000;

    def range = end - start;
    def p1 = if lower == f6 then f5 else
             if lower == f5 then f4 else
             if lower == f4 then f3 else
             if lower == f3 then f2 else
             if lower == f2 then f1 else
             f0;
    def p2 = if upper == f1 then f2 else
             if upper == f2 then f3 else
             if upper == f3 then f4 else
             if upper == f4 then f5 else
             if upper == f5 then f6 else
             f7;
    def n1 = end - range * p1;
    def n2 = end - range * p2;
    def upperRange = Max(n1, n2);
    def lowerRange = Min(n1, n2);

    plot inRange = if range > 0 then low < upperRange and low > lowerRange
                   else high < upperRange and high > lowerRange;
}

script PRZ {
    input x = 0;
    input a = 0;
    input b = 0;
    input c = 0;
    input abcd = 0;
    input xd1 = 0;
    input xd2 = 0;
    input cd1 = 0;
    input cd2 = 0;

    def XArng = (a - x);
    def ABrng = (a - b);
    def BCrng = (c - b);
    def Cr = AbsValue(BCrng) / AbsValue(ABrng);
    def Cret = if Cr >= 0.836 then 0.886 else
               if Cr >= 0.747 then 0.786 else
               if Cr >= 0.663 then 0.707 else
               if Cr >= 0.559 then 0.618 else
               if Cr >= 0.441 then 0.500 else
               0.382;
    def Cex = if 1 / Cret < cd1 then cd1 else if 1 / Cret > cd2 then cd2 else 1 / Cret;
    plot prz1 = c - (ABrng * abcd);
    plot prz2 = c - (BCrng * Cex);
    plot prz3 = a - (XArng * xd1);
    plot prz4 = a - (XArng * xd2);
    plot przMax = Max(Max(prz1, prz2), Max(prz3, prz4));
    plot przMin = Min(Min(prz1, prz2), Min(prz3, prz4));

}

input waveLength = 13;
input labelPoints = Yes;

def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = Min(waveLength - 1, lastBar - BarNumber());

def pHigh = high == Highest(high, waveLength) and high == GetValue(Highest(high, waveLength), -offset);
def pLow = low == Lowest(low, waveLength) and low == GetValue(Lowest(low, waveLength), -offset);

def cph = if pHigh[1] then 1 else cph[1] + 1;
def cpl = if pLow[1] then 1 else cpl[1] + 1;

def wHigh = ((pHigh and !pLow) or (pHigh and pLow and cpl < cph)) and cph >= waveLength;
def wLow = ((pLow and !pHigh) or (pLow and pHigh and cph < cpl)) and cpl >= waveLength;

def spHigh = if wLow[1] then high else if high > spHigh[1] then high else spHigh[1];
def bHigh = if wHigh then 0 else if wLow[1] then BarNumber() else if high >= spHigh[1] then BarNumber() else bHigh[1];
def spLow = if wHigh[1] then low else if low < spLow[1] then low else spLow[1];
def bLow = if wLow then 0 else if wHigh[1] then BarNumber() else if low <= spLow[1] then BarNumber() else bLow[1];

def cpwh = if wHigh[1] then 1 else cpwh[1] + 1;
def cpwl = if wLow[1] then 1 else cpwl[1] + 1;
def cnwh = fold i = 1 to lastBar with a = Double.NaN while IsNaN(a) do if GetValue(wHigh, -i) then i else Double.NaN;
def cnwl = fold j = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(wLow, -j) then j else Double.NaN;

def mwHigh = if !wHigh and (cpwl < cpwh) and BarNumber() == GetValue(bHigh[1], -cnwl) then 1 else Double.NaN;
def mwLow = if !wLow and (cpwh < cpwl) and BarNumber() == GetValue(bLow[1], -cnwh) then 1 else Double.NaN;

def peak = if IsNaN(close) then 0 else wHigh or !IsNaN(mwHigh);
def valley = if IsNaN(close) then 0 else wLow or !IsNaN(mwLow);

def lastPeakBar = HighestAll(if peak then BarNumber() else 0);
def lastPeak = BarNumber() == lastPeakBar;
def lastValleyBar = HighestAll(if valley then BarNumber() else 0);
def lastValley = BarNumber() == lastValleyBar;

def cpp = if peak[1] then 1 else cpp[1] + 1;
def cpv = if valley[1] then 1 else cpv[1] + 1;

def prevHigh = GetValue(high, cpp);
def prevLow = GetValue(low, cpv);
def prevHigh2 = GetValue(prevHigh, cpp);
def prevLow2 = GetValue(prevLow, cpv);

def cnp = if BarNumber() >= lastPeakBar then 0 else fold k = 1 to lastBar with c = 0 while c == 0 do if GetValue(peak, -k) then k else 0;
def cnp2 = cnp + GetValue(cnp, -cnp);
def cnv = if BarNumber() >= lastValleyBar then 0 else fold l = 1 to lastBar with d = 0 while d == 0 do if GetValue(valley, -l) then l else 0;
def cnv2 = cnv + GetValue(cnv, -cnv);

def nextHigh = if BarNumber() >= lastPeakBar then Double.NaN else GetValue(high, -cnp);
def nextLow = if BarNumber() >= lastValleyBar then Double.NaN else GetValue(low, -cnv);
def nextHigh2 = if IsNaN(GetValue(nextHigh, -cnp)) then nextHigh2[1] else GetValue(nextHigh, -cnp);
def nextLow2 = if IsNaN(GetValue(nextLow, -cnv)) then nextLow2[1] else GetValue(nextLow, -cnv);

def hf0 = 0.786;
def hf1 = 0.786;
def hf2 = 0.382;
def hf3 = 0.886;
def hf4 = 1.000;
def hf5 = 1.272;
def hf6 = 1.272;
def hf7 = 1.618;
def hf8 = 2.242;

input FudgeFactor = 0.8;
def FF = ATR()[1] * FudgeFactor;

def Lprz = waveLength * 2;
def blg1 = valley and inrange(prevLow, prevHigh, hf0, hf1);
def blg2 = peak and GetValue(blg1, cpv) and inrange(prevHigh, prevLow, hf2, hf3);
def blg3 = valley and GetValue(blg2, cpp);

def cv1 = if blg2 then 0 else cv1[1] + 1;
def blgz1 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz1[1], Double.NaN);
def blgz2 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz2[1], Double.NaN);

def blg4 = (low <= prevLow + ATR() * 2 and blg3 and !cnp and high >= blgz2 - FF) or (low <= prevLow and blg3 and cnp and (high >= (blgz2 - FF) and low <= (blgz1 + FF)));
def blg5 = if IsNaN(blg4) then 0 else blg4;
def blgX = valley and GetValue(blg5, -cnv2) and cnv2 > cnv;
def blgA = peak and GetValue(blgX, cpv);
def blgB = valley and GetValue(blgA, cpp);
def blgC = peak and GetValue(blgB, cpv);
def blgD = valley and GetValue(blgC, cpp);

def aBullWave = CompoundValue(1, if blgX and GetValue(blgD, -cnv2) then 1 else if blgD[1] and !blgX[1] then 0 else aBullWave[1], 0);

DefineGlobalColor("Bullish Labels", Color.LIGHT_GREEN);

AddChartBubble(blgX and labelPoints, low, "X", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgA and labelPoints, high, "A", GlobalColor("Bullish Labels"));
AddChartBubble(blgB and labelPoints, low, "B", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgC and labelPoints, high, "C", GlobalColor("Bullish Labels"));
AddChartBubble(blgD and labelPoints, low, "D", GlobalColor("Bullish Labels"), 0);



def abl = CompoundValue(1, if aBullWave and !aBullWave[1] then 0 else if aBullWave and blgC then 1 else abl[1], 0);
def blgPRZ1 = if IsNaN(close) then blgPRZ1[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz1 else Double.NaN;
def blgPRZ2 = if IsNaN(close) then blgPRZ2[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz2 else Double.NaN;

plot PRZlmax = blgPRZ1;
     PRZlmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZlmin = blgPRZ2;
     PRZlmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bullish PRZ", CreateColor(163, 221, 255));
AddCloud(PRZlmax, PRZlmin, GlobalColor("Bullish PRZ"));

def brg1 = peak and inrange(prevHigh, prevLow, hf0, hf1);
def brg2 = valley and GetValue(brg1, cpp) and inrange(prevLow, prevHigh, hf2, hf3);
def brg3 = peak and GetValue(brg2, cpv);

def cr1 = if brg2 then 0 else cr1[1] + 1;
def brgz1 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz1[1], Double.NaN);
def brgz2 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz2[1], Double.NaN);

def brg4 = (high >= prevHigh - ATR() * 2 and brg3 and !cnv and low <= brgz1 + FF) or (high >= prevHigh and brg3 and cnv and (low <= (brgz1 + FF) and high >= (brgz2 - FF)));
def brg5 = if IsNaN(brg4) then 0 else brg4;
def brgX = peak and GetValue(brg5, -cnp2) and cnp2 > cnp;
def brgA = valley and GetValue(brgX, cpp);
def brgB = peak and GetValue(brgA, cpv);
def brgC = valley and GetValue(brgB, cpp);
def brgD = peak and GetValue(brgC, cpv);

def aBearWave = if brgX and GetValue(brgD, -cnp2) then 1 else if brgD[1] and !brgX[1] then 0 else aBearWave[1];

DefineGlobalColor("Bearish Labels", Color.PINK);

AddChartBubble(brgX and labelPoints, high, "X", GlobalColor("Bearish Labels"));
AddChartBubble(brgA and labelPoints, low, "A", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgB and labelPoints, high, "B", GlobalColor("Bearish Labels"));
AddChartBubble(brgC and labelPoints, low, "C", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgD and labelPoints, high, "D", GlobalColor("Bearish Labels"));

def abr = CompoundValue(1, if aBearWave and !aBearWave[1] then 0 else if aBearWave and brgC then 1 else abr[1], 0);
def brgPRZ1 = if IsNaN(close) then brgPRZ1[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz1 else Double.NaN;
def brgPRZ2 = if IsNaN(close) then brgPRZ2[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz2 else Double.NaN;

plot PRZrmax = brgPRZ1;
     PRZrmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZrmin = brgPRZ2;
     PRZrmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bearish PRZ", CreateColor(226, 163, 255));
AddCloud(PRZrmax, PRZrmin, GlobalColor("Bearish PRZ"));

def mWave = if BarNumber() < lastPeakBar and valley then ((nextHigh - low) / cnp) else if BarNumber() < lastValleyBar and peak then ((nextLow - high) / cnv) else mWave[1];
def waveLine = if valley then low else if peak then high else waveLine[1] + mWave;

plot bullWave = if aBullWave then waveLine else Double.NaN;
     bullWave.SetDefaultColor(Color.WHITE);
     bullWave.SetLineWeight(2);
plot bearWave = if aBearWave then waveLine else Double.NaN;
     bearWave.SetDefaultColor(Color.WHITE);
     bearWave.SetLineWeight(2);

def mPeak = if BarNumber() < lastPeakBar and peak then ((nextHigh - high) / cnp) else mPeak[1];
def lPeak = if peak then high else lPeak[1] + mPeak;
def peakLine = if aBearWave then lPeak else Double.NaN;
AddCloud(peakLine, bearWave, Color.PINK);

def mValley = if BarNumber() < lastValleyBar and valley then ((nextLow - low) / cnv) else mValley[1];
def lvalley = if valley then low else lvalley[1] + mValley;
def valleyLine = if aBullWave then lvalley else Double.NaN;
AddCloud(bullWave, valleyLine, Color.LIGHT_GREEN);

#=============
input ShowTargetZones = No;

def brS = if IsNaN(nextHigh) then 0 else if nextHigh > high then 1 else 0;
def brT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.382 + high else brT1[1], Double.NaN);
def brT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.618 + high else brT2[1], Double.NaN);
def brT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.786 + high else brT3[1], Double.NaN);
def brT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.000 + high else brT4[1], Double.NaN);
def brT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.27 + high else brT5[1], Double.NaN);
def brT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.618 + high else brT6[1], Double.NaN);
plot bearT1 = if !ShowTargetZones then Double.NaN else brT1;
     bearT1.SetDefaultColor(Color.DARK_RED);
     bearT1.SetLineWeight(2);
plot bearT2 = if !ShowTargetZones then Double.NaN else brT2;
     bearT2.SetDefaultColor(Color.DARK_RED);
     bearT2.SetLineWeight(2);
plot bearT3 = if !ShowTargetZones then Double.NaN else brT3;
     bearT3.SetDefaultColor(Color.DARK_RED);
     bearT3.SetLineWeight(2);
plot bearT4 = if !ShowTargetZones then Double.NaN else brT4;
     bearT4.SetDefaultColor(Color.DARK_RED);
     bearT4.SetLineWeight(2);
plot bearT5 = if !ShowTargetZones then Double.NaN else brT5;
     bearT5.SetDefaultColor(Color.DARK_RED);
     bearT5.SetLineWeight(2);
plot bearT6 = if !ShowTargetZones then Double.NaN else brT6;
     bearT6.SetDefaultColor(Color.DARK_RED);
     bearT6.SetLineWeight(2);
AddCloud(bearT2, bearT3, Color.YELLOW);
AddCloud(bearT5, bearT6, Color.YELLOW);

def blS = if IsNaN(nextLow) then 0 else if nextLow < low then 1 else 0;
def blT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.382 + low else blT1[1], Double.NaN);
def blT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.618 + low else blT2[1], Double.NaN);
def blT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.786 + low else blT3[1], Double.NaN);
def blT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.000 + low else blT4[1], Double.NaN);
def blT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.27 + low else blT5[1], Double.NaN);
def blT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.618 + low else blT6[1], Double.NaN);
plot bullT1 = if !ShowTargetZones then Double.NaN else blT1;
     bullT1.SetDefaultColor(Color.DARK_GREEN);
     bullT1.SetLineWeight(2);
plot bullT2 = if !ShowTargetZones then Double.NaN else blT2;
     bullT2.SetDefaultColor(Color.DARK_GREEN);
     bullT2.SetLineWeight(2);
plot bullT3 = if !ShowTargetZones then Double.NaN else blT3;
     bullT3.SetDefaultColor(Color.DARK_GREEN);
     bullT3.SetLineWeight(2);
plot bullT4 = if !ShowTargetZones then Double.NaN else blT4;
     bullT4.SetDefaultColor(Color.DARK_GREEN);
     bullT4.SetLineWeight(2);
plot bullT5 = if !ShowTargetZones then Double.NaN else blT5;
     bullT5.SetDefaultColor(Color.DARK_GREEN);
     bullT5.SetLineWeight(2);
plot bullT6 = if !ShowTargetZones then Double.NaN else blT6;
    bullT6.SetDefaultColor(Color.DARK_GREEN);
     bullT6.SetLineWeight(2);
AddCloud(bullT3, bullT2, Color.YELLOW);
AddCloud(bullT6, bullT5, Color.YELLOW);

Crab pattern
Code:
# +--------------------------------------------------+

script InRange {
    input start = 0;
    input end = 0;
    input lower = 0;
    input upper = 0;

    def f0 = 0.264;
    def f1 = 0.382;
    def f2 = 0.500;
    def f3 = 0.618;
    def f4 = 0.707;
    def f5 = 0.786;
    def f6 = 0.886;
    def f7 = 1.000;

    def range = end - start;
    def p1 = if lower == f6 then f5 else
             if lower == f5 then f4 else
             if lower == f4 then f3 else
             if lower == f3 then f2 else
             if lower == f2 then f1 else
             f0;
    def p2 = if upper == f1 then f2 else
             if upper == f2 then f3 else
             if upper == f3 then f4 else
             if upper == f4 then f5 else
             if upper == f5 then f6 else
             f7;
    def n1 = end - range * p1;
    def n2 = end - range * p2;
    def upperRange = Max(n1, n2);
    def lowerRange = Min(n1, n2);

    plot inRange = if range > 0 then low < upperRange and low > lowerRange
                   else high < upperRange and high > lowerRange;
}

script PRZ {
    input x = 0;
    input a = 0;
    input b = 0;
    input c = 0;
    input abcd = 0;
    input xd1 = 0;
    input xd2 = 0;
    input cd1 = 0;
    input cd2 = 0;

    def XArng = (a - x);
    def ABrng = (a - b);
    def BCrng = (c - b);
    def Cr = AbsValue(BCrng) / AbsValue(ABrng);
    def Cret = if Cr >= 0.836 then 0.886 else
               if Cr >= 0.747 then 0.786 else
               if Cr >= 0.663 then 0.707 else
               if Cr >= 0.559 then 0.618 else
               if Cr >= 0.441 then 0.500 else
               0.382;
    def Cex = if 1 / Cret < cd1 then cd1 else if 1 / Cret > cd2 then cd2 else 1 / Cret;
    plot prz1 = c - (ABrng * abcd);
    plot prz2 = c - (BCrng * Cex);
    plot prz3 = a - (XArng * xd1);
    plot prz4 = a - (XArng * xd2);
    plot przMax = Max(Max(prz1, prz2), Max(prz3, prz4));
    plot przMin = Min(Min(prz1, prz2), Min(prz3, prz4));

}

input waveLength = 13;
input labelPoints = yes;

def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = Min(waveLength - 1, lastBar - BarNumber());

def pHigh = high == Highest(high, waveLength) and high == GetValue(Highest(high, waveLength), -offset);
def pLow = low == Lowest(low, waveLength) and low == GetValue(Lowest(low, waveLength), -offset);

def cph = if pHigh[1] then 1 else cph[1] + 1;
def cpl = if pLow[1] then 1 else cpl[1] + 1;

def wHigh = ((pHigh and !pLow) or (pHigh and pLow and cpl < cph)) and cph >= waveLength;
def wLow = ((pLow and !pHigh) or (pLow and pHigh and cph < cpl)) and cpl >= waveLength;

def spHigh = if wLow[1] then high else if high > spHigh[1] then high else spHigh[1];
def bHigh = if wHigh then 0 else if wLow[1] then BarNumber() else if high >= spHigh[1] then BarNumber() else bHigh[1];
def spLow = if wHigh[1] then low else if low < spLow[1] then low else spLow[1];
def bLow = if wLow then 0 else if wHigh[1] then BarNumber() else if low <= spLow[1] then BarNumber() else bLow[1];

def cpwh = if wHigh[1] then 1 else cpwh[1] + 1;
def cpwl = if wLow[1] then 1 else cpwl[1] + 1;
def cnwh = fold i = 1 to lastBar with a = Double.NaN while IsNaN(a) do if GetValue(wHigh, -i) then i else Double.NaN;
def cnwl = fold j = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(wLow, -j) then j else Double.NaN;

def mwHigh = if !wHigh and (cpwl < cpwh) and BarNumber() == GetValue(bHigh[1], -cnwl) then 1 else Double.NaN;
def mwLow = if !wLow and (cpwh < cpwl) and BarNumber() == GetValue(bLow[1], -cnwh) then 1 else Double.NaN;

def peak = if IsNaN(close) then 0 else wHigh or !IsNaN(mwHigh);
def valley = if IsNaN(close) then 0 else wLow or !IsNaN(mwLow);

def lastPeakBar = HighestAll(if peak then BarNumber() else 0);
def lastPeak = BarNumber() == lastPeakBar;
def lastValleyBar = HighestAll(if valley then BarNumber() else 0);
def lastValley = BarNumber() == lastValleyBar;

def cpp = if peak[1] then 1 else cpp[1] + 1;
def cpv = if valley[1] then 1 else cpv[1] + 1;

def prevHigh = GetValue(high, cpp);
def prevLow = GetValue(low, cpv);
def prevHigh2 = GetValue(prevHigh, cpp);
def prevLow2 = GetValue(prevLow, cpv);

def cnp = if BarNumber() >= lastPeakBar then 0 else fold k = 1 to lastBar with c = 0 while c == 0 do if GetValue(peak, -k) then k else 0;
def cnp2 = cnp + GetValue(cnp, -cnp);
def cnv = if BarNumber() >= lastValleyBar then 0 else fold l = 1 to lastBar with d = 0 while d == 0 do if GetValue(valley, -l) then l else 0;
def cnv2 = cnv + GetValue(cnv, -cnv);

def nextHigh = if BarNumber() >= lastPeakBar then Double.NaN else GetValue(high, -cnp);
def nextLow = if BarNumber() >= lastValleyBar then Double.NaN else GetValue(low, -cnv);
def nextHigh2 = if IsNaN(GetValue(nextHigh, -cnp)) then nextHigh2[1] else GetValue(nextHigh, -cnp);
def nextLow2 = if IsNaN(GetValue(nextLow, -cnv)) then nextLow2[1] else GetValue(nextLow, -cnv);

def hf0 = 0.382;
def hf1 = 0.618;
def hf2 = 0.382;
def hf3 = 0.886;
def hf4 = 1.618;
def hf5 = 1.618;
def hf6 = 1.618;
def hf7 = 2.618;
def hf8 = 3.618;

input FudgeFactor = 0.8;
def FF = ATR()[1] * FudgeFactor;

def Lprz = waveLength * 2;
def blg1 = valley and inrange(prevLow, prevHigh, hf0, hf1);
def blg2 = peak and GetValue(blg1, cpv) and inrange(prevHigh, prevLow, hf2, hf3);
def blg3 = valley and GetValue(blg2, cpp);

def cv1 = if blg2 then 0 else cv1[1] + 1;
def blgz1 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz1[1], Double.NaN);
def blgz2 = CompoundValue(1, if blg2 then prz(prevLow2, prevHigh, prevLow, high, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cv1 > Lprz and !GetValue(blg2, cpp) then Double.NaN else blgz2[1], Double.NaN);

def blg4 = (low <= prevLow + ATR() * 2 and blg3 and !cnp and high >= blgz2 - FF) or (low <= prevLow and blg3 and cnp and (high >= (blgz2 - FF) and low <= (blgz1 + FF)));
def blg5 = if IsNaN(blg4) then 0 else blg4;
def blgX = valley and GetValue(blg5, -cnv2) and cnv2 > cnv;
def blgA = peak and GetValue(blgX, cpv);
def blgB = valley and GetValue(blgA, cpp);
def blgC = peak and GetValue(blgB, cpv);
def blgD = valley and GetValue(blgC, cpp);

def aBullWave = CompoundValue(1, if blgX and GetValue(blgD, -cnv2) then 1 else if blgD[1] and !blgX[1] then 0 else aBullWave[1], 0);

DefineGlobalColor("Bullish Labels", Color.LIGHT_GREEN);

AddChartBubble(blgX and labelPoints, low, "X", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgA and labelPoints, high, "A", GlobalColor("Bullish Labels"));
AddChartBubble(blgB and labelPoints, low, "B", GlobalColor("Bullish Labels"), 0);
AddChartBubble(blgC and labelPoints, high, "C", GlobalColor("Bullish Labels"));
AddChartBubble(blgD and labelPoints, low, "D", GlobalColor("Bullish Labels"), 0);

def abl = CompoundValue(1, if aBullWave and !aBullWave[1] then 0 else if aBullWave and blgC then 1 else abl[1], 0);
def blgPRZ1 = if IsNaN(close) then blgPRZ1[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz1 else Double.NaN;
def blgPRZ2 = if IsNaN(close) then blgPRZ2[1] else if GetValue(abl, cv1) and GetValue(aBullWave, cv1) then blgz2 else Double.NaN;

plot PRZlmax = blgPRZ1;
     PRZlmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZlmin = blgPRZ2;
     PRZlmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bullish PRZ", CreateColor(163, 221, 255));
AddCloud(PRZlmax, PRZlmin, GlobalColor("Bullish PRZ"));

def brg1 = peak and inrange(prevHigh, prevLow, hf0, hf1);
def brg2 = valley and GetValue(brg1, cpp) and inrange(prevLow, prevHigh, hf2, hf3);
def brg3 = peak and GetValue(brg2, cpv);

def cr1 = if brg2 then 0 else cr1[1] + 1;
def brgz1 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMax else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz1[1], Double.NaN);
def brgz2 = CompoundValue(1, if brg2 then prz(prevHigh2, prevLow, prevHigh, low, hf4, hf5, hf6, hf7, hf8).przMin else if (peak or valley) and cr1 > Lprz and !GetValue(brg2, cpv) then Double.NaN else brgz2[1], Double.NaN);

def brg4 = (high >= prevHigh - ATR() * 2 and brg3 and !cnv and low <= brgz1 + FF) or (high >= prevHigh and brg3 and cnv and (low <= (brgz1 + FF) and high >= (brgz2 - FF)));
def brg5 = if IsNaN(brg4) then 0 else brg4;
def brgX = peak and GetValue(brg5, -cnp2) and cnp2 > cnp;
def brgA = valley and GetValue(brgX, cpp);
def brgB = peak and GetValue(brgA, cpv);
def brgC = valley and GetValue(brgB, cpp);
def brgD = peak and GetValue(brgC, cpv);

def aBearWave = if brgX and GetValue(brgD, -cnp2) then 1 else if brgD[1] and !brgX[1] then 0 else aBearWave[1];

DefineGlobalColor("Bearish Labels", Color.PINK);

AddChartBubble(brgX and labelPoints, high, "X", GlobalColor("Bearish Labels"));
AddChartBubble(brgA and labelPoints, low, "A", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgB and labelPoints, high, "B", GlobalColor("Bearish Labels"));
AddChartBubble(brgC and labelPoints, low, "C", GlobalColor("Bearish Labels"), 0);
AddChartBubble(brgD and labelPoints, high, "D", GlobalColor("Bearish Labels"));

def abr = CompoundValue(1, if aBearWave and !aBearWave[1] then 0 else if aBearWave and brgC then 1 else abr[1], 0);
def brgPRZ1 = if IsNaN(close) then brgPRZ1[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz1 else Double.NaN;
def brgPRZ2 = if IsNaN(close) then brgPRZ2[1] else if GetValue(abr, cr1) and GetValue(aBearWave, cr1) then brgz2 else Double.NaN;

plot PRZrmax = brgPRZ1;
     PRZrmax.SetDefaultColor(Color.DARK_GRAY);
plot PRZrmin = brgPRZ2;
     PRZrmin.SetDefaultColor(Color.DARK_GRAY);

DefineGlobalColor("Bearish PRZ", CreateColor(226, 163, 255));
AddCloud(PRZrmax, PRZrmin, GlobalColor("Bearish PRZ"));

def mWave = if BarNumber() < lastPeakBar and valley then ((nextHigh - low) / cnp) else if BarNumber() < lastValleyBar and peak then ((nextLow - high) / cnv) else mWave[1];
def waveLine = if valley then low else if peak then high else waveLine[1] + mWave;

plot bullWave = if aBullWave then waveLine else Double.NaN;
     bullWave.SetDefaultColor(Color.WHITE);
     bullWave.SetLineWeight(2);
plot bearWave = if aBearWave then waveLine else Double.NaN;
     bearWave.SetDefaultColor(Color.WHITE);
     bearWave.SetLineWeight(2);

def mPeak = if BarNumber() < lastPeakBar and peak then ((nextHigh - high) / cnp) else mPeak[1];
def lPeak = if peak then high else lPeak[1] + mPeak;
def peakLine = if aBearWave then lPeak else Double.NaN;
AddCloud(peakLine, bearWave, Color.PINK);

def mValley = if BarNumber() < lastValleyBar and valley then ((nextLow - low) / cnv) else mValley[1];
def lvalley = if valley then low else lvalley[1] + mValley;
def valleyLine = if aBullWave then lvalley else Double.NaN;
AddCloud(bullWave, valleyLine, Color.LIGHT_GREEN);

#=============
input ShowTargetZones = No;

def brS = if IsNaN(nextHigh) then 0 else if nextHigh > high then 1 else 0;
def brT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.382 + high else brT1[1], Double.NaN);
def brT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.618 + high else brT2[1], Double.NaN);
def brT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 0.786 + high else brT3[1], Double.NaN);
def brT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.000 + high else brT4[1], Double.NaN);
def brT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.27 + high else brT5[1], Double.NaN);
def brT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if brgD and !brS then (prevLow2 - prevHigh2) * 1.618 + high else brT6[1], Double.NaN);
plot bearT1 = if !ShowTargetZones then Double.NaN else brT1;
     bearT1.SetDefaultColor(Color.DARK_RED);
     bearT1.SetLineWeight(2);
plot bearT2 = if !ShowTargetZones then Double.NaN else brT2;
     bearT2.SetDefaultColor(Color.DARK_RED);
     bearT2.SetLineWeight(2);
plot bearT3 = if !ShowTargetZones then Double.NaN else brT3;
     bearT3.SetDefaultColor(Color.DARK_RED);
     bearT3.SetLineWeight(2);
plot bearT4 = if !ShowTargetZones then Double.NaN else brT4;
     bearT4.SetDefaultColor(Color.DARK_RED);
     bearT4.SetLineWeight(2);
plot bearT5 = if !ShowTargetZones then Double.NaN else brT5;
     bearT5.SetDefaultColor(Color.DARK_RED);
     bearT5.SetLineWeight(2);
plot bearT6 = if !ShowTargetZones then Double.NaN else brT6;
     bearT6.SetDefaultColor(Color.DARK_RED);
     bearT6.SetLineWeight(2);
AddCloud(bearT2, bearT3, Color.YELLOW);
AddCloud(bearT5, bearT6, Color.YELLOW);

def blS = if IsNaN(nextLow) then 0 else if nextLow < low then 1 else 0;
def blT1 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.382 + low else blT1[1], Double.NaN);
def blT2 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.618 + low else blT2[1], Double.NaN);
def blT3 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 0.786 + low else blT3[1], Double.NaN);
def blT4 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.000 + low else blT4[1], Double.NaN);
def blT5 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.27 + low else blT5[1], Double.NaN);
def blT6 = CompoundValue(1, if (brgA or blgA) then Double.NaN else if blgD and !blS then (prevHigh2 - prevLow2) * 1.618 + low else blT6[1], Double.NaN);
plot bullT1 = if !ShowTargetZones then Double.NaN else blT1;
     bullT1.SetDefaultColor(Color.DARK_GREEN);
     bullT1.SetLineWeight(2);
plot bullT2 = if !ShowTargetZones then Double.NaN else blT2;
     bullT2.SetDefaultColor(Color.DARK_GREEN);
     bullT2.SetLineWeight(2);
plot bullT3 = if !ShowTargetZones then Double.NaN else blT3;
     bullT3.SetDefaultColor(Color.DARK_GREEN);
     bullT3.SetLineWeight(2);
plot bullT4 = if !ShowTargetZones then Double.NaN else blT4;
     bullT4.SetDefaultColor(Color.DARK_GREEN);
     bullT4.SetLineWeight(2);
plot bullT5 = if !ShowTargetZones then Double.NaN else blT5;
     bullT5.SetDefaultColor(Color.DARK_GREEN);
     bullT5.SetLineWeight(2);
plot bullT6 = if !ShowTargetZones then Double.NaN else blT6;
     bullT6.SetDefaultColor(Color.DARK_GREEN);
     bullT6.SetLineWeight(2);
AddCloud(bullT3, bullT2, Color.YELLOW);
AddCloud(bullT6, bullT5, Color.YELLOW);
 
indicators I use every day from the gracious coders here on site.

AMM trend reverse indicator
Swing Waves Short indicator alert https://tos.mx/6RNZNjn
Swing Waves high/lo caveat/line https://tos.mx/u1oP8kx
BLT Fibs https://tos.mx/kCvSfpQ
MA Cloud Crossover thinkorswim Sharing (tos.mx)
Horizontal Price Line https://tos.mx/NKVDVVr
Laguerre Upper price fractals https://tos.mx/njcc5VR
Gap Finder https://tos.mx/rSfIC3D
Latest RAF_Stochastic lwr thinkorswim Sharing (tos.mx)
Wolf Wave_Ben's thinkorswim Sharing (tos.mx)
Wave 1 thinkorswim Sharing (tos.mx)
Supertrend Laguerre thinkorswim Sharing (tos.mx)
thinkorswim Sharing (tos.mx)
Candle Overlay thinkorswim Sharing (tos.mx)
Advanced Volume Indicator thinkorswim Sharing (tos.mx)

Grid Share thinkorswim Sharing (tos.mx)

2S2her6.png
 
Last edited:
https://drive.google.com/file/d/1TwDI5i11PyndeZ7Wwo_RA7k3GGr99vXd/view?usp=sharing

Video shared for this morning's apple open the video is a bit long my intentions were to catch the bounce and we did.

https://tos.mx/CGFrYH3

I hope this helps someone out there.

The screenshot was a bit long taken after this morning's open and I closed after morning's low set following the plan via indicators. Next play I will annotate this stuff it's fun. What I am recording is Apple I watch the Short Waves Indicator closely as I do Advanced Market Waves for reverse signals when I see the reversal indicator and I know by my daily fibs are uptight we have to wait and remember I want a tight high price before going short. So I took the short for plus 20% and I am somewhat conservative.

Fibs are my first alert, AMM my second alert, Short Waves indicator seal the deal after I hear a short wave alert its usually a matter of time before other indicators confirm. You can wait till short waves posts a horizontal red line and you see a down arrow it's about to feel for the market really traders choice. I took this one down to the lo and closed because the ticker set its bottom fib line after open which is usually the case so it's very important to wait for the bottom fib to set. Generally, you have only one shot at this bottom so use your 5min chart, well I do. Next and once we set the lower day boundary price a ticker needs to test its upper boundary ie, daily fib line, and or watch fibs for lower lo' generally.

Use your upper time frames down to where you want to trade, always begin from the top down to access the market for your ticker.
 
Last edited:
I very much like the first script with targets is another way to verify paired with the BLT Fibs and the Short Waves indicator.

Thanks...I very much like the first script with targets is another way to verify paired with the BLT Fibs and the Short Waves indicator. I'll leave it up for next week I also like the ABCD labels..another verification fort is the upper Laguerre pivot line.
 
Last edited:
No, I'm sorry I tend to experiment with the many great charts and indicators written on-site. Here is a chart I have used for the last 2 wks with very good results. But it seems I always come back to use my favorites.

thinkorswim Sharing (tos.mx)

TTJn5yC.png
 
I've studied the RSI_Laguerre_Lines_wTargets and it is very telling with reversals. When used in conjunction with an 8/21 exponential moving average /vwap and bens Wolfe wave script that gives support and resistance lines this a very powerful combination. Can also throw in DMI arrows and definitely the lower indicators shown on my chart. I found that the short waves script isn't necessary when using the RSI_Laguerre_Lines_wTargets and the only arrows I use are the Laguerre and DMI arrows. Through various time frames, one can also use the Laguerre levels as support/resistance lines.
 
Last edited:
I like your set up . The problem I have is that on my Pc screen upper part of this chart is so flat maybe like half of inch is unreadable .Lower part like volume and power x indicators are so large . All this is out of scale and proportion . I just clicked on this link you provided thinkorswim sharing (tos.mx) . What did I do wrong ? Need some technical help please . Hum you also try unchecking fit studies.
One thing you try is go-to style, settings, price axis and choose the expansion area the % up and down boxes and play with the settings
 
Status
Not open for further replies.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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