Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. //@version=5
  2.  
  3. indicator(title='UCS_Murrey\'s Math Oscillator', shorttitle='UCS_MMLO', overlay=false, precision=4)
  4. import loxx/loxxdynamiczone/3
  5. import jdehorty/KernelFunctions/2
  6. // Inputs
  7. length = input.int(432, minval=10, title='Look back Length')
  8. mult = input(0.186, title='Mutiplier; Only Supports 0.125 = 1/8')
  9. lines = input(true, title='Show Murrey Math Fractals')
  10. bc = input(false, title='Show Bar Colors Based On Oscillator')
  11. roundn(x, n) =>
  12. mult2 = 1
  13. if n != 0
  14. for i = 1 to math.abs(n)
  15. mult2 := mult2 * 10
  16.  
  17. n >= 0 ? math.round(x * mult2) / mult2 : math.round(x / mult2) * mult2
  18. // Donchanin Channel
  19. test1 = array.new<float>(1441)
  20. test1.set(0,na)
  21. test2 = array.new<float>(1441)
  22. test2.set(0,na)
  23. len = input(0)
  24. for i = 1 to 144
  25. test1.set(i, ta.lowest(low,i))
  26. test2.set(i, ta.highest(high,i))
  27. loavg = array.avg(test1)
  28. hiavg = array.avg(test2)
  29. range_1 = hiavg - loavg
  30. multiplier = range_1 * mult
  31. midline = loavg + multiplier * 4
  32.  
  33. oscillator = (close - midline) / (range_1 / 2)
  34. if oscillator > 1.125
  35. oscillator := 1.125
  36. if oscillator < -1.125
  37. oscillator := -1.125
  38.  
  39. len2 = input(12)
  40. maosc = KernelFunctions.locallyPeriodic(oscillator,len2,len2,len2)
  41. col2 = color.gray
  42. if maosc[0]>maosc[1]
  43. col2 := color.green
  44. if maosc[0]<maosc[1]
  45. col2 := color.red
  46. a = oscillator > 0 and oscillator < mult * 2
  47. b = oscillator > 0 and oscillator < mult * 4
  48. c = oscillator > 0 and oscillator < mult * 6
  49. d = oscillator > 0 and oscillator < mult * 8
  50.  
  51. z = oscillator < 0 and oscillator > -mult * 2
  52. y = oscillator < 0 and oscillator > -mult * 4
  53. x = oscillator < 0 and oscillator > -mult * 6
  54. w = oscillator < 0 and oscillator > -mult * 8
  55.  
  56. colordef = a ? #00bcd4 : b ? #089981 : c ? #4caf50 : d ? #008000 : z ? #ffeb3b : y ? #ff9800 : x ? #f23645 : w ? #801922 : color.blue
  57. if oscillator == -1.125
  58. colordef := #1848cc
  59. if oscillator == 1.125
  60. colordef := #26c6da
  61. plot(oscillator, color=colordef, title='Murrey Math Oscillator', style=plot.style_columns, trackprice = true)
  62. a1 = plot(maosc, color= col2, style = plot.style_stepline, linewidth = 2)
  63.  
  64. plot(0, title='Zero Line', color=color.new(color.white, 0), linewidth=2)
  65. plot(lines == 1 ? mult * 1 : na, title=' Positive 1', color=color.new(color.gray, 0), linewidth=1)
  66. plot(lines == 1 ? mult * 2 : na, title='First Positive Quadrant', color=color.new(color.white, 0), linewidth=1)
  67. plot(lines == 1 ? mult * 3 : na, title=' Positive 3', color=color.new(color.gray, 0), linewidth=1)
  68. plot(lines == 1 ? mult * 4 : na, title='Second Positive Quadrant', color=color.new(color.white, 0), linewidth=1)
  69. plot(lines == 1 ? mult * 5 : na, title=' Positive 5', color=color.new(color.gray, 0), linewidth=1)
  70. p3 = plot(lines == 1 ? mult * 6 : na, title='Third Positive Quadrant', color=color.new(color.white, 0), linewidth=2)
  71. plot(lines == 1 ? mult * 7 : na, title=' Positive 7', color=color.new(color.gray, 0), linewidth=1)
  72. p4 = plot(lines == 1 ? mult * 8 : na, title='Fourth Positive Quadrant', color=color.new(color.white, 0), linewidth=1)
  73. plot(lines == 1 ? -mult * 1 : na, title=' Negative 1', color=color.new(color.gray, 0), linewidth=1)
  74. plot(lines == 1 ? -mult * 2 : na, title='First Negative Quadrant', color=color.new(color.white, 0), linewidth=1)
  75. plot(lines == 1 ? -mult * 3 : na, title=' Negative 3', color=color.new(color.gray, 0), linewidth=1)
  76. plot(lines == 1 ? -mult * 4 : na, title='Second Negative Quadrant', color=color.new(color.white, 0), linewidth=1)
  77. plot(lines == 1 ? -mult * 5 : na, title=' Negative 5', color=color.new(color.gray, 0), linewidth=1)
  78. p2 = plot(lines == 1 ? -mult * 6 : na, title='Third Negative Quadrant', color=color.new(color.white, 0), linewidth=2)
  79. plot(lines == 1 ? -mult * 7 : na, title=' Negative 7', color=color.new(color.gray, 0), linewidth=1)
  80. p1 = plot(lines == 1 ? -mult * 8 : na, title='Fourth Negative Quadrant', color=color.new(color.white, 0), linewidth=1)
  81.  
  82. fill(p1, p2, color=color.rgb(76, 175, 79, 77))
  83. fill(p3, p4, color=color.rgb(255, 82, 82, 77))
  84.  
  85. // Bar Color Oversold and Overbought
  86. bcolor = bc == 1 ? colordef : na
  87. barcolor(bcolor)
  88. prob1 = input(0.99)
  89. prob2 = input(0.80)
  90. bl1 = loxxdynamiczone.dZone("buy", oscillator, prob1, 27)
  91. sl1 = loxxdynamiczone.dZone("sell", oscillator, prob1, 27)
  92. zli = loxxdynamiczone.dZone("sell", oscillator, prob2, 27)
  93. zli2 = loxxdynamiczone.dZone("buy", oscillator, prob2, 27)
  94. mid = loxxdynamiczone.dZone("buy", oscillator, .50, 27)
  95. plot(bl1, color = color.red, style = plot.style_stepline, linewidth = 2)
  96. plot(sl1, color = color.green, style = plot.style_stepline, linewidth = 2)
  97.  
  98. a2 = plot(mid, color = color.white, style = plot.style_stepline, trackprice = true)
  99. col3 = color.gray
  100. stepoffup = false
  101. if oscillator[1]<=sl1[1] and oscillator[0]>sl1[0] and oscillator[1]<0
  102. stepoffup := true
  103. plotshape(stepoffup,style=shape.triangleup, color=color.green, location=location.bottom)
  104. if oscillator > maosc
  105. col3 := color.rgb(76, 175, 79, 77)
  106. if oscillator < maosc
  107. col3 := color.rgb(255, 82, 82, 77)
  108. if maosc > mid
  109. col3 := color.rgb(76, 175, 79, 77)
  110. if maosc < mid
  111. col3 := color.rgb(255, 82, 82, 77)
  112. fill(a1,a2,color = col3)
  113. hist0a = oscillator[0]
  114. hist1a = oscillator[1]
  115. hist2a = oscillator[2]
  116. hist3a = oscillator[3]
  117. hist4a = oscillator[4]
  118. hist0 = roundn(hist0a,4)
  119. hist1 = roundn(hist1a,4)
  120. hist2 = roundn(hist2a,4)
  121. hist3 = roundn(hist3a,4)
  122. hist4 = roundn(hist4a,4)
  123. var table hista0 = table.new(position.top_right, 1, 7)
  124. col4 = color.gray
  125. col5 = color.gray
  126. col6 = color.gray
  127. col7 = color.gray
  128. if hist0 > hist1
  129. col4 := color.green
  130. if hist0 < hist1
  131. col4 := color.red
  132. if hist1 > hist2
  133. col5 := color.green
  134. if hist1 < hist2
  135. col5 := color.red
  136. if hist2 > hist3
  137. col6 := color.green
  138. if hist2 < hist3
  139. col6 := color.red
  140. if hist3 > hist4
  141. col7 := color.green
  142. if hist3 < hist4
  143. col7 := color.red
  144.  
  145. var mastate = "null"
  146. macol = color.gray
  147. if oscillator > maosc
  148. mastate := "above MA"
  149. macol := color.green
  150. if oscillator < maosc
  151. mastate := "below MA"
  152. macol := color.red
  153.  
  154. var pstate = "null"
  155. pcol = color.gray
  156. if oscillator > mid
  157. pstate := "above 0.5"
  158. pcol := color.green
  159. if oscillator < mid
  160. pstate := "below 0.5"
  161. pcol := color.red
  162.  
  163. var mapstate = "null"
  164. mapcol = color.gray
  165. if maosc > mid
  166. mapstate := "MA above 0.5"
  167. mapcol := color.green
  168. if maosc < mid
  169. mapstate := "MA below 0.5"
  170. mapcol := color.red
  171. if barstate.islast
  172. table.cell(hista0, 0, 0, str.tostring(hist0), text_color = col4)
  173. table.cell(hista0, 0, 1, str.tostring(hist1), text_color = col5)
  174. table.cell(hista0, 0, 2, str.tostring(hist2), text_color = col6)
  175. table.cell(hista0, 0, 3, str.tostring(hist3), text_color = col7)
  176. table.cell(hista0, 0, 4, str.tostring(mastate), text_color = macol)
  177. table.cell(hista0, 0, 5, str.tostring(pstate), text_color = pcol)
  178. table.cell(hista0, 0, 6, str.tostring(mapstate), text_color = mapcol)
  179.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement