Guest User

Untitled

a guest
Nov 14th, 2023
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. //@version=5
  2. indicator("Williams Fractals", shorttitle="Beppo Fractals", overlay=true)
  3.  
  4. n = input.int(2, title="Periods", minval=2)
  5. fractalBars = input("3", title="3 or 5 Bar Fractal")
  6.  
  7. // Function to get daily timeframe data
  8. getDailyData(value) =>
  9. request.security(syminfo.tickerid, "D", value, lookahead=barmerge.lookahead_on)
  10.  
  11. geth4Data(value) =>
  12. request.security(syminfo.tickerid,"240",value,lookahead=barmerge.lookahead_on)
  13. // Logic
  14. var bool dnFractalD = na
  15. var bool upFractalD = na
  16.  
  17. var bool dnFractalh4 = na
  18. var bool upFractalh4 = na
  19.  
  20.  
  21. if fractalBars == "5"
  22. dnFractalD := (getDailyData(high[n-2]) < getDailyData(high[n])) and
  23. (getDailyData(high[n-1]) < getDailyData(high[n])) and
  24. (getDailyData(high[n+1]) < getDailyData(high[n])) and
  25. (getDailyData(high[n+2]) < getDailyData(high[n]))
  26.  
  27. upFractalD := (getDailyData(low[n-2]) > getDailyData(low[n])) and
  28. (getDailyData(low[n-1]) > getDailyData(low[n])) and
  29. (getDailyData(low[n+1]) > getDailyData(low[n])) and
  30. (getDailyData(low[n+2]) > getDailyData(low[n]))
  31.  
  32.  
  33. dnFractalh4 := (geth4Data(high[n-2]) < geth4Data(high[n])) and
  34. (geth4Data(high[n-1]) < geth4Data(high[n])) and
  35. (geth4Data(high[n+1]) < geth4Data(high[n])) and
  36. (geth4Data(high[n+2]) < geth4Data(high[n]))
  37.  
  38. upFractalh4 := (geth4Data(low[n-2]) > geth4Data(low[n])) and
  39. (geth4Data(low[n-1]) > geth4Data(low[n])) and
  40. (geth4Data(low[n+1]) > geth4Data(low[n])) and
  41. (geth4Data(low[n+2]) > geth4Data(low[n]))
  42. else
  43. if fractalBars == "3"
  44. dnFractalD := (getDailyData(high[n-1]) < getDailyData(high[n])) and
  45. (getDailyData(high[n+1]) < getDailyData(high[n]))
  46. upFractalD := (getDailyData(low[n-1]) > getDailyData(low[n])) and
  47. (getDailyData(low[n+1]) > getDailyData(low[n]))
  48.  
  49. dnFractalh4 := (geth4Data(high[n-1]) < geth4Data(high[n])) and
  50. (geth4Data(high[n+1]) < geth4Data(high[n]))
  51. upFractalh4 := (geth4Data(low[n-1]) > geth4Data(low[n])) and
  52. (geth4Data(low[n+1]) > geth4Data(low[n]))
  53.  
  54. // Plot the fractals as shapes on the chart.
  55. plotshape(dnFractalh4, style=shape.triangledown, location=location.abovebar, size=size.tiny, offset=-2, color=color.blue)
  56. plotshape(upFractalh4, style=shape.triangleup, location=location.belowbar, size=size.tiny, offset=-2, color=color.blue)
  57.  
  58. plotshape(dnFractalD, style=shape.triangledown, location=location.abovebar, size=size.tiny, offset=-2, color=color.red)
  59. plotshape(upFractalD, style=shape.triangleup, location=location.belowbar, size=size.tiny, offset=-2, color=color.red)
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment