RicardoSantos

[RS]Fractals V5

15587 visualizzazioni
2337
Update to the zigzag , now it ignores the second top/bottom untill it finds a inversed top/bottom. TBTBTBTBTBTBTB instead of TBBTTBTBBTBTTB.

Updated to V8, link bellow in the related ideas.
Script open-source

Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?
study(title="[RS]Fractals V5", overlay=true)
//  ||---   V1: Added filtering option
//  ||---   V4: diferentiated Bill Williams fractals and regular fractals as a choice
//  ||---       added zigzag option
//  ||---   V5: modified zigzag
//  ||---   Fractal Recognition:
filterBW = input(false, 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 = not showZigZag ? na : (
        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)

Commenti

LuckyMouse asked:
'Hi Ricardo - been looking again at FractalsV5 - ShowSwingHL feature - looks fantastic with labels option - but often flags late on the peak after the main swingHL peak. Couldnt understand the pinescript at all so dont know how it works? It would be cool and maybe profitable if i could understand how its calculated (logic wise) and maybe collaborate on poss new techniques to flag it at the extremes? Any chance you can explain concept and rational. Im a spreadsheet developer in finance and into various TA so understand most concepts. Bests LM'

the delay is caused by the need for confirmation of the fractal pattern as it needs to wait for the next 2 candles after the top/bottom to confirm that we have a extreme.
there is also another issue due to pinescript currently not having looping capability s:
• its not possible to change a lower top for the next when 2 top or 2bottoms form in a row and the second is higher/lower then the previous.

+14 Rispondi
How to interpret it?
Please explain.
+1 Rispondi
great stuff, would you be able to add ratio between two adjacent legs? like retracement %.

tks
Rispondi
@jacxia81, its possible only as a numeric variable plot (it shows after the indicators name on the top left of the chart), or another indicator just for that purpose
Rispondi
Home Screener azioni Screener forex Screener cripto Calendario economico Su di noi Caratteristiche Grafico Costi Invita un amico Regolamento Centro di supporto Soluzioni per broker & siti web Widget Librerie grafiche Libreria grafica leggera Blog & Novità Twitter