xmd79

Pi Cycle Bitcoin High/Low

Oct 5th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © @NoCreditsLeft
  3.  
  4. //@version=4
  5. study("Pi Cycle Bitcoin High/Low", shorttitle="Pi Cycle Bitcoin High/Low", overlay=true)
  6.  
  7. //Create Inputs for the 4 MAs, and Visual
  8.  
  9. lowma_long = input(471, minval=1, title="BTC Low - Long SMA")
  10. is_show_lowma1 = input(true, type=input.bool, title="Show Low Long SMA?")
  11.  
  12. lowema_short = input(150, minval=1, title="BTC Low - Short EMA")
  13. is_show_lowma2 = input(true, type=input.bool, title="Show Low Short EMA?")
  14.  
  15. hima_long = input(350, minval=1, title="BTC High - Long SMA")
  16. is_show_hima1 = input(true, type=input.bool, title="Show High Long SMA?")
  17.  
  18. hima_short = input(111, minval=1, title="BTC High - Short SMA")
  19. is_show_hima2 = input(true, type=input.bool, title="Show High Short SMA?")
  20.  
  21. //Set resolution to the Daily Chart
  22. resolution = input('D', type=input.string, title="Time interval")
  23.  
  24. //Run the math for the 4 MAs
  25. ma_long_low = security(syminfo.tickerid, resolution, sma(close, lowma_long)*745)/1000
  26. ema_short_low = security(syminfo.tickerid, resolution, ema(close, lowema_short))
  27. ma_long_hi = security(syminfo.tickerid, resolution, sma(close, hima_long)*2)
  28. ma_short_hi = security(syminfo.tickerid, resolution, sma(close, hima_short))
  29.  
  30. //Set SRC
  31. src = security(syminfo.tickerid, resolution, close)
  32.  
  33. //Plot the 4 MAs
  34. plot(is_show_lowma1?ma_long_low:na, color=color.red, linewidth=2, title="Low Long MA")
  35. var lowma_long_label = label.new(x = bar_index, y = lowma_long, color = color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.red, text = "BTC Low - Long SMA")
  36. label.set_xy(lowma_long_label, x = bar_index, y = ma_long_low)
  37.  
  38. plot(is_show_lowma2?ema_short_low:na, color=color.green, linewidth=2, title="Low Short EMA")
  39. var lowema_short_label = label.new(x = bar_index, y = lowema_short, color = color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.green, text = "BTC Low - Short EMA")
  40. label.set_xy(lowema_short_label, x = bar_index, y = ema_short_low)
  41.  
  42. plot(is_show_hima1?ma_long_hi:na, color=color.white, linewidth=2, title="High Long MA")
  43. var hima_long_label = label.new(x = bar_index, y = hima_long, color = color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.white, text = "BTC High - Long MA")
  44. label.set_xy(hima_long_label, x = bar_index, y = ma_long_hi)
  45.  
  46. plot(is_show_hima2?ma_short_hi:na, color=color.yellow, linewidth=2, title="High Short MA")
  47. var hima_short_label = label.new(x = bar_index, y = hima_short, color = color.rgb(0, 0, 0, 100), style = label.style_label_left, textcolor = color.yellow, text = "BTC High - Short MA")
  48. label.set_xy(hima_short_label, x = bar_index, y = ma_short_hi)
  49.  
  50. //Find where the MAs cross each other
  51. PiCycleLow = crossunder(ema_short_low, ma_long_low) ? src + (src/100 * 10) : na
  52. PiCycleHi = crossunder(ma_long_hi, ma_short_hi) ? src + (src/100 * 10) : na
  53.  
  54. //Create Labels
  55. plotshape(PiCycleLow, text="Pi Cycle Low", color=color.navy, textcolor=color.white, style=shape.labelup,size=size.normal, location=location.belowbar, title="Cycle Low")
  56. plotshape(PiCycleHi, text="Pi Cycle High", color=color.teal, textcolor=color.white, style=shape.labeldown,size=size.normal, location=location.abovebar, title="Cycle High")
  57.  
  58. //Generate vertical lines at the BTC Halving Dates
  59. isDate(y, m, d) =>
  60. val = timestamp(y,m,d)
  61. if val <= time and val > time[1]
  62. true
  63. else
  64. false
  65.  
  66. // First Halving
  67. if isDate(2012, 11, 28)
  68. line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, style=line.style_dashed, color=color.yellow)
  69. label.new(bar_index, low, text="1st Halving - Nov 28, 2012", style=label.style_label_upper_left, textcolor=color.yellow, color=color.black, textalign=text.align_right, yloc=yloc.belowbar)
  70.  
  71. // Second Halving
  72. if isDate(2016, 7, 9)
  73. line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, style=line.style_dashed, color=color.yellow)
  74. label.new(bar_index, low, text="2nd Halving - Jul 9, 2016", style=label.style_label_upper_left, textcolor=color.yellow, color=color.black, textalign=text.align_right, yloc=yloc.belowbar)
  75.  
  76. // Third Halving
  77. if isDate(2020, 5, 11)
  78. line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, style=line.style_dashed, color=color.yellow)
  79. label.new(bar_index, low, text="3rd Halving - May 11, 2020", style=label.style_label_upper_left, textcolor=color.yellow, color=color.black, textalign=text.align_right, yloc=yloc.belowbar)
  80.  
  81. // Fourth Halving
  82. //if isDate(2024, 3, 26)
  83. // line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, style=line.style_dashed, color=color.yellow)
  84. // label.new(bar_index, low, text="4th Halving - March 26, 2024", style=label.style_label_upper_left, textcolor=color.yellow, color=color.black, textalign=text.align_right, yloc=yloc.belowbar)
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment