xmd79

PO4C<^>Model

Aug 10th, 2023
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. //@version=5
  2. indicator(title='PO4C<^>Model', overlay=true)
  3.  
  4. showBarColors = input(false)
  5. filterBW = input(false, title="filter Bill Williams Fractals:")
  6. doubleFractalCheck = input(true, title="Check for Double Fractal")
  7.  
  8. // Fractal Recognition Functions
  9. isRegularFractal(mode) =>
  10. mode == 1 and high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] or
  11. mode == -1 and low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0]
  12.  
  13. isBWFractal(mode) =>
  14. mode == 1 and high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] or
  15. mode == -1 and low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0]
  16.  
  17. isDoubleFractal(mode) =>
  18. mode == 1 and high[4] < high[3] and high[3] == high[2] and high[2] > high[1] and high[1] > high[0] or
  19. mode == -1 and low[4] > low[3] and low[3] == low[2] and low[2] < low[1] and low[1] < low[0]
  20.  
  21. filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
  22. filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
  23.  
  24. plotshape(filteredtopf, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
  25. plotshape(filteredbotf, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.lime, offset=-2)
  26.  
  27. filtereddoubltopf = doubleFractalCheck ? isDoubleFractal(1) : false
  28. filtereddoublbotf = doubleFractalCheck ? isDoubleFractal(-1) : false
  29.  
  30. plotshape(filtereddoubltopf, title='Filtered Double Top Fractals', style=shape.circle, location=location.abovebar, color=color.purple, offset=-2)
  31. plotshape(filtereddoublbotf, title='Filtered Double Bottom Fractals', style=shape.circle, location=location.belowbar, color=color.purple, offset=-2)
  32.  
  33. /// Higher Highs, Lower Highs, Higher Lows, Lower Lows
  34. ShowHHLL = input(false)
  35.  
  36. higherhighValue = ta.valuewhen(filteredtopf == true, high[2], 1)
  37. higherhighValuePrev = ta.valuewhen(filteredtopf == true, high[2], 0)
  38. higherhighCond = higherhighValue < higherhighValuePrev and ta.valuewhen(filteredtopf == true, high[2], 2) < higherhighValuePrev
  39. higherhigh = filteredtopf == false ? false : higherhighCond
  40.  
  41. lowerhighValue = ta.valuewhen(filteredtopf == true, high[2], 1)
  42. lowerhighValuePrev = ta.valuewhen(filteredtopf == true, high[2], 0)
  43. lowerhighCond = lowerhighValue > lowerhighValuePrev and ta.valuewhen(filteredtopf == true, high[2], 2) > lowerhighValuePrev
  44. lowerhigh = filteredtopf == false ? false : lowerhighCond
  45.  
  46. higherlowValue = ta.valuewhen(filteredbotf == true, low[2], 1)
  47. higherlowValuePrev = ta.valuewhen(filteredbotf == true, low[2], 0)
  48. higherlowCond = higherlowValue < higherlowValuePrev and ta.valuewhen(filteredbotf == true, low[2], 2) < higherlowValuePrev
  49. higherlow = filteredbotf == false ? false : higherlowCond
  50.  
  51. lowerlowValue = ta.valuewhen(filteredbotf == true, low[2], 1)
  52. lowerlowValuePrev = ta.valuewhen(filteredbotf == true, low[2], 0)
  53. lowerlowCond = lowerlowValue > lowerlowValuePrev and ta.valuewhen(filteredbotf == true, low[2], 2) > lowerlowValuePrev
  54. lowerlow = filteredbotf == false ? false : lowerlowCond
  55.  
  56. plotshape(ShowHHLL ? higherhigh : na, title='Higher High', style=shape.square, location=location.abovebar, color=color.maroon, text="HH", offset=-2)
  57. plotshape(ShowHHLL ? lowerhigh : na, title='Lower High', style=shape.square, location=location.abovebar, color=color.maroon, text="LH", offset=-2)
  58. plotshape(ShowHHLL ? higherlow : na, title='High Low', style=shape.square, location=location.belowbar, color=color.green, text="HL", offset=-2)
  59. plotshape(ShowHHLL ? lowerlow : na, title='Lower Low', style=shape.square, location=location.belowbar, color=color.green, text="LL", offset=-2)
  60.  
  61. // Fractals from higher Timeframe
  62. ShowTimeFractals1 = input(false)
  63. timeframe1 = input("240")
  64.  
  65. isTFFractal(mode, tf) =>
  66. mode == 1 and higherhighValue >= request.security(syminfo.tickerid, tf, high) or
  67. mode == -1 and lowerlowValue <= request.security(syminfo.tickerid, tf, low)
  68.  
  69. higherhhigh = higherhigh == false ? false : isTFFractal(1, timeframe1)
  70. lowerllow = lowerlow == false ? false : isTFFractal(-1, timeframe1)
  71.  
  72. plotshape(ShowTimeFractals1 ? higherhhigh : na, title='Timed Top Fractals', style=shape.square, location=location.abovebar, color=color.maroon, text="", offset=-2)
  73. plotshape(ShowTimeFractals1 ? lowerllow : na, title='Timed Bottom Fractals', style=shape.square, location=location.belowbar, color=color.green, text="", offset=-2)
  74.  
  75. // ZigZag
  76. showZigZag = input(true)
  77.  
  78. istop = ShowTimeFractals1 ? (higherhhigh ? true : false) : (filteredtopf ? true : false)
  79. isbot = ShowTimeFractals1 ? (lowerllow ? true : false) : (filteredbotf ? true : false)
  80. topcount = ta.barssince(istop)
  81. botcount = ta.barssince(isbot)
  82.  
  83. zigzag = (
  84. istop and topcount[1] > botcount[1] ? high[2] :
  85. isbot and topcount[1] < botcount[1] ? low[2] :
  86. na )
  87.  
  88. plot(not showZigZag ? na : zigzag, title='ZigZag', color=color.white, offset=-2)
  89.  
  90. bc = zigzag and high[2] == zigzag ? color.red : zigzag and low[2] == zigzag ? color.lime : color.silver
  91. barcolor(showBarColors ? bc : na, offset=-2)
  92.  
Advertisement
Add Comment
Please, Sign In to add comment