Advertisement
xmd79

Moon + DWMQY • Yata

Jan 29th, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 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. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  3. //@version=5
  4.  
  5. indicator("Moon + DWMQY • Yata",
  6. overlay = true,
  7. scale=scale.none)
  8.  
  9. // --------------------
  10. groupMP = "Moon Phases"
  11. // --------------------
  12.  
  13. new = input.time(defval=timestamp("2021-01-13:05:00"), title="Reference Date", inline="D", group=groupMP)
  14.  
  15. show_moon = input.bool(true, title="Show Moons |", inline="MO", group=groupMP)
  16. show_bg = input.bool(true, title="Background |", inline="MO", group=groupMP)
  17. show_vl = input.bool(false, title="Lines", inline="MO", group=groupMP)
  18.  
  19. buy = input.string("Full Moon", options=["New Moon", "Full Moon", "Higher Moon", "Lower Moon"], title="", inline="MO1", group=groupMP)
  20. sell = input.string("New Moon", options=["New Moon", "Full Moon", "Higher Moon", "Lower Moon"], title="", inline="MO2", group=groupMP)
  21.  
  22. nmooncol = input.color(color.new(color.black, 20), title="", inline="MO2", group=groupMP)
  23. fmooncol = input.color(color.new(color.silver, 20), title="", inline="MO1", group=groupMP)
  24.  
  25. longcol = input.color(color.new(color.silver, 90), title="|", inline="MO1", group=groupMP)
  26. shortcol = input.color(color.new(color.silver, 95), title="|", inline="MO2", group=groupMP)
  27.  
  28. longvlcol = input.color(color.new(color.silver, 80), title="|", inline="MO1", group=groupMP)
  29. shortvlcol = input.color(color.new(color.silver, 80), title="|", inline="MO2", group=groupMP)
  30.  
  31. // --------------------
  32.  
  33. n = bar_index
  34. cycle = 2551442876.8992
  35. day = 8.64e+7
  36. diff = (new + time + day * 2) % cycle / cycle
  37.  
  38. // --------------------
  39.  
  40. newmoon = ta.crossover(diff, .5)
  41. fullmoon = diff < diff[1]
  42.  
  43. plotshape(show_moon and newmoon ? low : na, "New Moon", shape.circle, location.bottom, nmooncol, size=size.small)
  44. plotshape(show_moon and fullmoon ? high : na, "Full Moon", shape.circle, location.top, fmooncol, size=size.small)
  45.  
  46. plot(show_vl and newmoon ? 1 : na, style=plot.style_histogram, color=longvlcol, title="New Moon")
  47. plot(show_vl and fullmoon ? 1 : na, style=plot.style_histogram, color=shortvlcol, title="Full Moon")
  48.  
  49. // --------------------
  50.  
  51. msrc = close
  52. var bool long = na
  53. var bool short = na
  54. if buy == "New Moon"
  55. long := newmoon
  56. long
  57. else if buy == "Full Moon"
  58. long := fullmoon
  59. long
  60. else if buy == "Higher Moon"
  61. long := ta.valuewhen(newmoon or fullmoon, msrc, 0) > ta.valuewhen(newmoon or fullmoon, msrc, 1)
  62. long
  63. else
  64. long := ta.valuewhen(newmoon or fullmoon, msrc, 0) < ta.valuewhen(newmoon or fullmoon, msrc, 1)
  65. long
  66.  
  67. // --------------------
  68.  
  69. if sell == "New Moon"
  70. short := newmoon
  71. short
  72. else if sell == "Full Moon"
  73. short := fullmoon
  74. short
  75. else if sell == "Higher Moon"
  76. short := ta.valuewhen(newmoon or fullmoon, msrc, 0) > ta.valuewhen(newmoon or fullmoon, msrc, 1)
  77. short
  78. else
  79. short := ta.valuewhen(newmoon or fullmoon, msrc, 0) < ta.valuewhen(newmoon or fullmoon, msrc, 1)
  80. short
  81.  
  82. // --------------------
  83.  
  84. var pos = 0
  85. if long
  86. pos := 1
  87.  
  88. if short
  89. pos := -1
  90.  
  91. bgcolor(show_bg and pos == 1 ? longcol : show_bg ? shortcol : na)
  92.  
  93. // ------------------------------
  94. groupCA = "D, W, M, Q & Y Breaks"
  95. // ------------------------------
  96.  
  97. color_d = input.color(color.new(color.silver, 80) , title="" , inline="d", group=groupCA)
  98. color_w = input.color(color.new(#42a5f5, 60) , title="" , inline="w", group=groupCA)
  99. color_m = input.color(color.new(#388e3c, 50) , title="" , inline="m", group=groupCA)
  100. color_q = input.color(color.new(#fbc02d, 40) , title="" , inline="q", group=groupCA)
  101. color_y = input.color(color.new(#d32f2f, 20) , title="" , inline="y", group=groupCA)
  102.  
  103. show_d = input.bool(false, title="Show Daily" , inline="d", group=groupCA)
  104. show_w = input.bool(false, title="Show Weekly" , inline="w", group=groupCA)
  105. show_m = input.bool(true, title="Show Monthly" , inline="m", group=groupCA)
  106. show_q = input.bool(true, title="Show Quarterly" , inline="q", group=groupCA)
  107. show_y = input.bool(true, title="Show Yearly" , inline="y", group=groupCA)
  108.  
  109. // ------------------------------
  110.  
  111. is_new(resolution) =>
  112. t = time(resolution)
  113. not na(t) and (na(t[1]) or t > t[1])
  114.  
  115. is_new_year() =>
  116. is_new("12M")
  117. is_new_quarter() =>
  118. is_new("3M") and (timeframe.isweekly or timeframe.isdaily or timeframe.isintraday)
  119. is_new_month() =>
  120. is_new("M") and not timeframe.ismonthly
  121. is_new_week() =>
  122. is_new("W") and not timeframe.isweekly and not timeframe.ismonthly
  123. is_new_day() =>
  124. is_new("D")
  125. is_minutes() =>
  126. timeframe.isminutes
  127.  
  128. // ------------------------------
  129.  
  130. plot_year() =>
  131. is_new_year()
  132. plot_quarter() =>
  133. is_new_quarter() //not is_new_year() and is_new_quarter()
  134. plot_month() =>
  135. is_new_month() //not is_new_year() and not is_new_quarter() and is_new_month()
  136. plot_week() =>
  137. is_new_week() //not is_new_year() and not is_new_quarter() and not is_new_month() and is_new_week()
  138. plot_day() =>
  139. is_new_day() and is_minutes() //not is_new_year() and not is_new_quarter() and not is_new_month() and not is_new_week() and is_new_day() and is_minutes()
  140.  
  141. plot(show_y and plot_year() ? 1 : na , style=plot.style_histogram, linewidth=2, color=color_y, title="Year Break")
  142. plot(show_q and plot_quarter() ? 1 : na , style=plot.style_histogram, linewidth=1, color=color_q, title="Quarter Break")
  143. plot(show_m and plot_month() ? 1 : na , style=plot.style_histogram, linewidth=1, color=color_m, title="Month Break")
  144. plot(show_w and plot_week() ? 1 : na , style=plot.style_histogram, linewidth=1, color=color_w, title="Week Break")
  145. plot(show_d and plot_day() ? 1 : na , style=plot.style_histogram, linewidth=1, color=color_d, title="Day Break")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement