Advertisement
JustUncleL

Fractals and Pivots R1

Feb 12th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. //@version=2
  2.  
  3. study(title="Fractals and Pivots R1 by JustUncleL", shorttitle="FRACTAL R1", overlay=true)
  4.  
  5. // By: JustUncleL
  6. // Date: 13-Feb-2017
  7. // Version: R1
  8. //
  9. // Description:
  10. // This indicator display fractals, fractal levels, Pivot Points and HH/LL points.
  11. //
  12. // references:
  13. // - [RS]Fractal Levels by RicardoSantos
  14. //
  15. // Modifications:
  16. // R1 - original.
  17. //
  18. //
  19. //
  20. ShowPivots = input(true)
  21. ShowPivotLabels = input(false)
  22. ShowPivotNumbers = input(false)
  23. ShowFractals = input(true)
  24. ShowFractalLevels= input(false)
  25. ShowHHLL_ = input(false)
  26. ShowHHLL = ShowPivots?false:ShowHHLL_
  27. filterBW_ = input(false,"Show Ideal Fractals Only")
  28. //
  29. //
  30. // --- CONSTANTS ---
  31. DodgerBlue = #1E90FF
  32. filterBW = ShowPivots?true: filterBW_
  33. // --- /CONTANTS ---
  34.  
  35. close_ = security(ticker, period, close)
  36. open_ = security(ticker, period, open)
  37. high_ = security(ticker, period, high)
  38. low_ = security(ticker, period, low)
  39.  
  40. // ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
  41. // ||-----------------------------------------------------------------------------------------------------||
  42. // ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
  43. isIdealFractal(mode) =>
  44. ret = mode == 1 ? high_[5] < high_[4] and high_[4] < high_[3] and high_[3] > high_[2] and high_[2] > high_[1] :
  45. mode == -1 ? low_[5] > low_[4] and low_[4] > low_[3] and low_[3] < low_[2] and low_[2] < low_[1] : false
  46.  
  47. isRegularFractal(mode) =>
  48. ret = mode == 1 ? high_[5] < high_[3] and high_[4] < high_[3] and high_[3] > high_[2] and high_[3] > high_[1] :
  49. mode == -1 ? low_[5] > low_[3] and low_[4] > low_[3] and low_[3] < low_[2] and low_[3] < low_[1] : false
  50.  
  51. // ||-----------------------------------------------------------------------------------------------------||
  52.  
  53. filteredtopf = filterBW ? isIdealFractal(1) : isRegularFractal(1)
  54. filteredbotf = filterBW ? isIdealFractal(-1) : isRegularFractal(-1)
  55.  
  56. //plotshape(ShowFractals? filteredtopf :na, title='Filtered Top Fractals', style=shape.triangleup, location=location.abovebar, color=green, offset=-3, transp=20)
  57. //plotshape(ShowFractals? filteredbotf :na, title='Filtered Bottom Fractals', style=shape.triangledown, location=location.belowbar, color=red, offset=-3, transp=20)
  58. topf = isRegularFractal(1)
  59. botf = isRegularFractal(-1)
  60.  
  61. topfractals = filteredtopf ? high_[3] : topfractals[1]
  62. botfractals = filteredbotf ? low_[3] : botfractals[1]
  63.  
  64. topfcolor = topfractals != topfractals[1] ? na : green
  65. botfcolor = botfractals != botfractals[1] ? na : red
  66.  
  67. // ||-----------------------------------------------------------------------------------------------------||
  68. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  69. higherhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_[3], 1) < valuewhen(filteredtopf == true, high_[3], 0) and
  70. (ShowPivots or valuewhen(filteredtopf == true, high_[3], 2) < valuewhen(filteredtopf == true, high_[3], 0)))
  71. lowerhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_[3], 1) > valuewhen(filteredtopf == true, high_[3], 0) and
  72. (ShowPivots or valuewhen(filteredtopf == true, high_[3], 2) > valuewhen(filteredtopf == true, high_[3], 0)))
  73. higherlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_[3], 1) < valuewhen(filteredbotf == true, low_[3], 0) and
  74. (ShowPivots or valuewhen(filteredbotf == true, low_[3], 2) < valuewhen(filteredbotf == true, low_[3], 0)))
  75. lowerlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_[3], 1) > valuewhen(filteredbotf == true, low_[3], 0) and
  76. (ShowPivots or valuewhen(filteredbotf == true, low_[3], 2) > valuewhen(filteredbotf == true, low_[3], 0)))
  77.  
  78. // If selected Display the HH/LL above/below candle.
  79. plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.square, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
  80. plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.square, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
  81. plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.square, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
  82. plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.square, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)
  83.  
  84. // If Selected Display Pivot points
  85. plotshape(ShowPivots and ShowPivotLabels? higherhigh : na, title='Higher High', style=shape.cross, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
  86. plotshape(ShowPivots and not ShowPivotLabels? higherhigh? high :na : na, title='Higher High+', style=shape.cross, location=location.abovebar, color=maroon, offset=-3,transp=0)
  87.  
  88. plotshape(ShowPivots and ShowPivotLabels? lowerhigh : na, title='Lower High', style=shape.cross, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
  89. plotshape(ShowPivots and not ShowPivotLabels? lowerhigh? high : na : na, title='Lower High+', style=shape.cross, location=location.abovebar, color=maroon, offset=-3,transp=0)
  90. //
  91. plotshape(ShowPivots and ShowPivotLabels? higherlow : na, title='Higher Low', style=shape.cross, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
  92. plotshape(ShowPivots and not ShowPivotLabels? higherlow? low: na : na, title='Higher Low+', style=shape.cross, location=location.belowbar, color=green, offset=-3,transp=0)
  93. //
  94. plotshape(ShowPivots and ShowPivotLabels? lowerlow : na, title='Lower Low', style=shape.cross, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)
  95. plotshape(ShowPivots and not ShowPivotLabels? lowerlow? low : na : na, title='Lower Low+', style=shape.cross, location=location.belowbar, color=green, offset=-3,transp=0)
  96. //
  97. // Number the Pivot candle fractal positions above or below candles
  98. plotchar(ShowPivots and ShowPivotNumbers? filteredtopf: na, title='High 1u', location=location.abovebar, color=maroon, char="1", offset=-5,transp=0)
  99. plotchar(ShowPivots and ShowPivotNumbers? filteredtopf: na, title='High 2u', location=location.abovebar, color=maroon, char="2", offset=-4,transp=0)
  100. plotchar(ShowPivots and ShowPivotNumbers ? filteredtopf: na, title='High 2d', location=location.abovebar, color=maroon, char="2", offset=-2,transp=0)
  101. plotchar(ShowPivots and ShowPivotNumbers ? filteredtopf: na, title='High 1d', location=location.abovebar, color=maroon, char="1", offset=-1,transp=0)
  102. //
  103. plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 1d', location=location.belowbar, color=green, char="1", offset=-5,transp=0)
  104. plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 2d', location=location.belowbar, color=green, char="2", offset=-4,transp=0)
  105. plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 2u', location=location.belowbar, color=green, char="2", offset=-2,transp=0)
  106. plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 1u', location=location.belowbar, color=green, char="1", offset=-1,transp=0)
  107.  
  108. havespot = not ShowPivots or (ShowPivots and not(higherhigh or lowerhigh or higherlow or lowerlow))
  109. plotshape(havespot and ShowFractals? topf :na, title='Regular Top Fractals', style=shape.triangleup, location=location.abovebar, color=red, offset=-3,transp=0)
  110. plotshape(havespot and ShowFractals? botf :na, title='Regular Bottom Fractals', style=shape.triangledown, location=location.belowbar, color=green, offset=-3,transp=0)
  111.  
  112. plot(ShowFractalLevels? topfractals : na, color=topfcolor, transp=0, linewidth=2)
  113. plot(ShowFractalLevels? botfractals : na, color=botfcolor, transp=0, linewidth=2)
  114.  
  115. //
  116. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement