EXPERIMENTAL:
added a missing triangulation(ZCD)
added a missing triangulation(ZCD)
study(title="[RS]Fractal Pattern Recognition (3 Triangles) V1.1", overlay=false) // ||--- Fractal Recognition: filterBW = input(true, title="filter Bill Williams Fractals:") filterFractals = input(false, title="Filter fractals using extreme method:") length = input(24, title="Extreme Window:") regulartopfractal = high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] regularbotfractal = low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] billwtopfractal = filterBW ? false : (high[4] < high[2] and high[3] < high[2] and high[2] > high[1] and high[2] > high[0] ? true : false) billwbotfractal = filterBW ? false : (low[4] > low[2] and low[3] > low[2] and low[2] < low[1] and low[2] < low[0] ? true : false) ftop = filterBW ? regulartopfractal : regulartopfractal or billwtopfractal fbot = filterBW ? regularbotfractal : regularbotfractal or billwbotfractal topf = ftop ? high[2] >= highest(high, length) ? true : false : false botf = fbot ? low[2] <= lowest(low, length) ? true : false : false filteredtopf = filterFractals ? topf : ftop filteredbotf = filterFractals ? botf : fbot // ||------------------------------------------------------------------------------------------------------ //plotshape(filteredtopf, style=shape.triangledown, location=location.abovebar, color=red, text="•", offset=-2) //plotshape(filteredbotf, style=shape.triangleup, location=location.belowbar, color=lime, text="•", offset=-2) // ||--- V1 : Added Swing High/Low Option //ShowSwingsHL = input(true) //highswings = filteredtopf == false ? na : valuewhen(filteredtopf == true, high[2], 2) < valuewhen(filteredtopf == true, high[2], 1) and valuewhen(filteredtopf == true, high[2], 1) > valuewhen(filteredtopf == true, high[2], 0) //lowswings = filteredbotf == false ? na : valuewhen(filteredbotf == true, low[2], 2) > valuewhen(filteredbotf == true, low[2], 1) and valuewhen(filteredbotf == true, low[2], 1) < valuewhen(filteredbotf == true, low[2], 0) //--------------------------------------------------------------------------------------------------------- // ||--- Offset calculation: // ||--- unable to use, plots cant use series for offset value... //hsoffset = n-valuewhen(ftop == true, n[2], 1) //lsoffset = n-valuewhen(fbot == true, n[2], 1) //--------------------------------------------------------------------------------------------------------- //plotshape(ShowSwingsHL ? highswings : na, style=shape.triangledown, location=location.abovebar, color=maroon, text="H", offset=-2) //plotshape(ShowSwingsHL ? lowswings : na, style=shape.triangleup, location=location.belowbar, color=green, text="L", offset=-2) // ||--- V2 : Plot Lines based on the fractals. //showchannel = input(true) //plot(showchannel ? (filteredtopf ? high[2] : na) : na, color=black, offset=-2) //plot(showchannel ? (filteredbotf ? low[2] : na) : na, color=black, offset=-2) //--------------------------------------------------------------------------------------------------------- // ||--- HLswings channel: unable to offset values //plot(showchannel ? (highswings ? high[2] : na) : na, color=black, offset=-2) //plot(showchannel ? (lowswings ? low[2] : na) : na, color=black, offset=-2) //---------------------------------------------------------------------------------------------------------- // ||--- ZigZag: //showZigZag = input(true) istop = filteredtopf ? true : false isbot = filteredbotf ? true : false topcount = barssince(istop) botcount = barssince(isbot) zigzag = ( istop and topcount[1] > botcount[1] ? high[2] : isbot and topcount[1] < botcount[1] ? low[2] : na ) //zigzag = not showZigZag ? na : ( filteredtopf == true ? high[2] : filteredbotf == true ? low[2] : na ) //plot(zigzag, color=black, offset=-2) // ||--- Pattern Recognition: //istop() => zigzag == filteredtopf //isbot() => zigzag == filteredbotf z = valuewhen(zigzag, zigzag, 6) y = valuewhen(zigzag, zigzag, 5) x = valuewhen(zigzag, zigzag, 4) a = valuewhen(zigzag, zigzag, 3) b = valuewhen(zigzag, zigzag, 2) c = valuewhen(zigzag, zigzag, 1) d = valuewhen(zigzag, zigzag, 0) zyx = (abs(x-y)/abs(z-y)) zyb = (abs(b-y)/abs(z-y)) zyd = (abs(d-y)/abs(z-y)) zab = (abs(b-a)/abs(z-a)) zad = (abs(d-a)/abs(z-a)) zcd = (abs(d-c)/abs(z-c)) yxa = (abs(a-x)/abs(y-x)) yxc = (abs(c-x)/abs(y-x)) ybc = (abs(a-c)/abs(y-c)) xab = (abs(b-a)/abs(x-a)) xad = (abs(a-d)/abs(x-a)) abc = (abs(b-c)/abs(a-b)) bcd = (abs(c-d)/abs(b-c)) plot(title='', series=zyx, color=change(zyx) != 0 ? na : navy, transp=0, offset=-2) plot(title='', series=zyb, color=change(zyb) != 0 ? na : navy, transp=15, offset=-2) plot(title='', series=zyd, color=change(zyd) != 0 ? na : navy, transp=30, offset=-2) plot(title='', series=zab, color=change(zab) != 0 ? na : navy, transp=45, offset=-2) plot(title='', series=zad, color=change(zad) != 0 ? na : navy, transp=60, offset=-2) plot(title='', series=zcd, color=change(zcd) != 0 ? na : navy, transp=75, offset=-2) plot(title='', series=yxa, color=change(yxa) != 0 ? na : fuchsia, transp=0, offset=-2) plot(title='', series=yxc, color=change(yxc) != 0 ? na : fuchsia, transp=25, offset=-2) plot(title='', series=ybc, color=change(ybc) != 0 ? na : fuchsia, transp=50, offset=-2) plot(title='', series=xab, color=change(xab) != 0 ? na : black, transp=0, offset=-2) plot(title='', series=xad, color=change(xad) != 0 ? na : black, transp=15, offset=-2) plot(title='', series=abc, color=change(abc) != 0 ? na : black, transp=30, offset=-2) plot(title='', series=bcd, color=change(bcd) != 0 ? na : black, transp=45, offset=-2) plotshape(change(zyx) != 0 ? zyx : na, text="ZYX", color=navy, transp=0, location=location.absolute, offset=-2) plotshape(change(zyb) != 0 ? zyb : na, text="ZYB", color=navy, transp=15, location=location.absolute, offset=-2) plotshape(change(zyd) != 0 ? zyd : na, text="ZYD", color=navy, transp=30, location=location.absolute, offset=-2) plotshape(change(zab) != 0 ? zab : na, text="ZAB", color=navy, transp=45, location=location.absolute, offset=-2) plotshape(change(zad) != 0 ? zad : na, text="ZAD", color=navy, transp=60, location=location.absolute, offset=-2) plotshape(change(zcd) != 0 ? zcd : na, text="ZAD", color=navy, transp=75, location=location.absolute, offset=-2) plotshape(change(yxa) != 0 ? yxa : na, text="YXA", color=fuchsia, transp=0, location=location.absolute, offset=-2) plotshape(change(yxc) != 0 ? yxc : na, text="YXC", color=fuchsia, transp=25, location=location.absolute, offset=-2) plotshape(change(ybc) != 0 ? ybc : na, text="YBC", color=fuchsia, transp=50, location=location.absolute, offset=-2) plotshape(change(xab) != 0 ? xab : na, text="XAB", color=black, transp=0, location=location.absolute, offset=-2) plotshape(change(xad) != 0 ? xad : na, text="XAD", color=black, transp=15, location=location.absolute, offset=-2) plotshape(change(abc) != 0 ? abc : na, text="ABC", color=black, transp=30, location=location.absolute, offset=-2) plotshape(change(bcd) != 0 ? bcd : na, text="BCD", color=black, transp=45, location=location.absolute, offset=-2) //bgcolor(xd <= 0.8 and xd >= 0.6 ? black : na, transp=25) //plot(topcounter, color=green, offset=-2) //plot(botcounter, color=red, offset=-2)