Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title='PO4C<^>Model', overlay=true)
- showBarColors = input(false)
- filterBW = input(false, title="filter Bill Williams Fractals:")
- doubleFractalCheck = input(true, title="Check for Double Fractal")
- // Fractal Recognition Functions
- isRegularFractal(mode) =>
- mode == 1 and high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] or
- mode == -1 and low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0]
- isBWFractal(mode) =>
- mode == 1 and high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] or
- mode == -1 and low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0]
- isDoubleFractal(mode) =>
- mode == 1 and high[4] < high[3] and high[3] == high[2] and high[2] > high[1] and high[1] > high[0] or
- mode == -1 and low[4] > low[3] and low[3] == low[2] and low[2] < low[1] and low[1] < low[0]
- filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
- filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
- plotshape(filteredtopf, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
- plotshape(filteredbotf, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.lime, offset=-2)
- filtereddoubltopf = doubleFractalCheck ? isDoubleFractal(1) : false
- filtereddoublbotf = doubleFractalCheck ? isDoubleFractal(-1) : false
- plotshape(filtereddoubltopf, title='Filtered Double Top Fractals', style=shape.circle, location=location.abovebar, color=color.purple, offset=-2)
- plotshape(filtereddoublbotf, title='Filtered Double Bottom Fractals', style=shape.circle, location=location.belowbar, color=color.purple, offset=-2)
- /// Higher Highs, Lower Highs, Higher Lows, Lower Lows
- ShowHHLL = input(false)
- higherhighValue = ta.valuewhen(filteredtopf == true, high[2], 1)
- higherhighValuePrev = ta.valuewhen(filteredtopf == true, high[2], 0)
- higherhighCond = higherhighValue < higherhighValuePrev and ta.valuewhen(filteredtopf == true, high[2], 2) < higherhighValuePrev
- higherhigh = filteredtopf == false ? false : higherhighCond
- lowerhighValue = ta.valuewhen(filteredtopf == true, high[2], 1)
- lowerhighValuePrev = ta.valuewhen(filteredtopf == true, high[2], 0)
- lowerhighCond = lowerhighValue > lowerhighValuePrev and ta.valuewhen(filteredtopf == true, high[2], 2) > lowerhighValuePrev
- lowerhigh = filteredtopf == false ? false : lowerhighCond
- higherlowValue = ta.valuewhen(filteredbotf == true, low[2], 1)
- higherlowValuePrev = ta.valuewhen(filteredbotf == true, low[2], 0)
- higherlowCond = higherlowValue < higherlowValuePrev and ta.valuewhen(filteredbotf == true, low[2], 2) < higherlowValuePrev
- higherlow = filteredbotf == false ? false : higherlowCond
- lowerlowValue = ta.valuewhen(filteredbotf == true, low[2], 1)
- lowerlowValuePrev = ta.valuewhen(filteredbotf == true, low[2], 0)
- lowerlowCond = lowerlowValue > lowerlowValuePrev and ta.valuewhen(filteredbotf == true, low[2], 2) > lowerlowValuePrev
- lowerlow = filteredbotf == false ? false : lowerlowCond
- plotshape(ShowHHLL ? higherhigh : na, title='Higher High', style=shape.square, location=location.abovebar, color=color.maroon, text="HH", offset=-2)
- plotshape(ShowHHLL ? lowerhigh : na, title='Lower High', style=shape.square, location=location.abovebar, color=color.maroon, text="LH", offset=-2)
- plotshape(ShowHHLL ? higherlow : na, title='High Low', style=shape.square, location=location.belowbar, color=color.green, text="HL", offset=-2)
- plotshape(ShowHHLL ? lowerlow : na, title='Lower Low', style=shape.square, location=location.belowbar, color=color.green, text="LL", offset=-2)
- // Fractals from higher Timeframe
- ShowTimeFractals1 = input(false)
- timeframe1 = input("240")
- isTFFractal(mode, tf) =>
- mode == 1 and higherhighValue >= request.security(syminfo.tickerid, tf, high) or
- mode == -1 and lowerlowValue <= request.security(syminfo.tickerid, tf, low)
- higherhhigh = higherhigh == false ? false : isTFFractal(1, timeframe1)
- lowerllow = lowerlow == false ? false : isTFFractal(-1, timeframe1)
- plotshape(ShowTimeFractals1 ? higherhhigh : na, title='Timed Top Fractals', style=shape.square, location=location.abovebar, color=color.maroon, text="", offset=-2)
- plotshape(ShowTimeFractals1 ? lowerllow : na, title='Timed Bottom Fractals', style=shape.square, location=location.belowbar, color=color.green, text="", offset=-2)
- // ZigZag
- showZigZag = input(true)
- istop = ShowTimeFractals1 ? (higherhhigh ? true : false) : (filteredtopf ? true : false)
- isbot = ShowTimeFractals1 ? (lowerllow ? true : false) : (filteredbotf ? true : false)
- topcount = ta.barssince(istop)
- botcount = ta.barssince(isbot)
- zigzag = (
- istop and topcount[1] > botcount[1] ? high[2] :
- isbot and topcount[1] < botcount[1] ? low[2] :
- na )
- plot(not showZigZag ? na : zigzag, title='ZigZag', color=color.white, offset=-2)
- bc = zigzag and high[2] == zigzag ? color.red : zigzag and low[2] == zigzag ? color.lime : color.silver
- barcolor(showBarColors ? bc : na, offset=-2)
Advertisement
Add Comment
Please, Sign In to add comment