Advertisement
xmd79

Rotation Cycles Graph

Jan 6th, 2024
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 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. // Β© VanHe1sing
  3.  
  4. //@version=5
  5. indicator("Rotation Cycles Graph", shorttitle = "[RC]")
  6.  
  7. //----------------------------------------------------------------------------------------------------------------------
  8. // - User Inputs
  9. //----------------------------------------------------------------------------------------------------------------------
  10. int z_len = input(40, 'Length', inline = "Z score", group = "Z Score")
  11. int z_smooth = input(5, 'Smooth', inline = "Z score", group = "Z Score")
  12.  
  13. int barScale = input.int(140, "Bar Scale:", step= 5, group = "Graph Settings")
  14. int offset = input.int(200, "X Axis Graph Position:", step= 5, group = "Graph Settings")
  15. int len_tail = input.int(30, "Length of the Tail", step= 5, group = "Graph Settings")
  16.  
  17. bool showbarcolor = input.bool(false, "Show colors of bars")
  18.  
  19. series float src = close
  20.  
  21. //----------------------------------------------------------------------------------------------------------------------
  22. // - Functions
  23. //----------------------------------------------------------------------------------------------------------------------
  24. z_score(src, len)=>
  25. float u = ta.sma(src, len)
  26. s = array.new<float>(10000,0)
  27. array.push(s, src)
  28. stdv = array.stdev(s)
  29. z = (src-u)/stdv
  30. z
  31.  
  32. // The Ehlers Loop
  33. EhlerLoop(float xPosition, float yPosition, color Color,
  34. int Segments, int BarScale, int Offset) =>
  35. if barstate.islast
  36. var aSegments = array.new<line> (Segments )
  37. var aNodes = array.new<label>(Segments + 1)
  38. for i=0 to Segments
  39. float Y2 = nz(yPosition[ i ])
  40. int X2 = int(nz(xPosition[ i ]) * BarScale)
  41. int X1 = int(nz(xPosition[1 + i]) * BarScale)
  42. float Y1 = nz(yPosition[1 + i])
  43. X2 := math.min(500, X2 + Offset) + bar_index
  44. X1 := math.min(500, X1 + Offset) + bar_index
  45. if i < Segments
  46. width = int(4 * (Segments - i) / Segments + 1)
  47. line.delete(array.get(aSegments, i))
  48. segment= line.new(X1, Y1, X2, Y2, color=color.new(Color, 60),
  49. style=line.style_solid, width=width)
  50. array.set( aSegments, i, segment)
  51. nodeSize = i==0 ? size.normal : size.small
  52. nodeChar = i==0 ? "β¦Ώ"+ syminfo.ticker : ""
  53. label.delete(array.get(aNodes, i))
  54. node = label.new(X2, Y2, nodeChar, size=nodeSize,
  55. color=#00000000, textcolor=Color,
  56. style=label.style_label_center)
  57.  
  58. // Draws Box
  59. drawBox(float Width, int Offset, float Height, color Color) =>
  60. if barstate.islast
  61. var Box = box.new(
  62. bar_index, Height * 0.5, bar_index, Height * -0.5,
  63. border_color=Color, border_style=line.style_dotted,
  64. bgcolor=color.new(Color, 95), text_size=size.small,
  65. text="",
  66. text_color=Color, text_valign=text.align_bottom)
  67. width = int(Width)
  68. box.set_left( Box, int(bar_index - width) + Offset)
  69. box.set_right(Box, int(bar_index + width) + Offset)
  70.  
  71. // Draw Lable
  72. labels(offset_, h, txt, color, size = size.normal)=>
  73. if barstate.islast
  74. label.new(bar_index + offset + offset_, h, txt, style = label.style_none,
  75. textcolor = color, size = size)
  76.  
  77. //----------------------------------------------------------------------------------------------------------------------
  78. // - X & Y defining
  79. //----------------------------------------------------------------------------------------------------------------------
  80. src := ta.hma(z_score(src, z_len), z_smooth)
  81.  
  82. x_ = src/40
  83. x = x_ > 1 ? 1 : x_ < -1 ? -1 : x_
  84.  
  85. y_ = ta.change(x, z_len-15)
  86. y = y_ > 1 ? 1 : y_ < -1 ? -1 : y_
  87.  
  88. //----------------------------------------------------------------------------------------------------------------------
  89. // - Visualization
  90. //----------------------------------------------------------------------------------------------------------------------
  91.  
  92. // Graph Boxes
  93. drawBox(barScale, offset, 2.0, color.white)
  94. drawBox(barScale+25, offset, 2.8, color.white)
  95. // Lines
  96. // Horizontal line
  97. hline( 0.0, "Zero", #808000, hline.style_dotted)
  98. // Vertical line
  99. if barstate.islast
  100. X = offset + bar_index
  101. var zero = line.new(X, -1.0, X, 1.0, color=#808000,
  102. style=line.style_dotted, width=1)
  103. line.set_x1(zero, X + 1)
  104. line.set_x2(zero, X)
  105.  
  106. // Colors
  107. color = x > 0 and y > 0 ? color.lime
  108. : x > 0 and y < 0 ? color.orange
  109. : x < 0 and y < 0 ? color.red
  110. : x < 0 and y > 0 ? color.aqua : na
  111.  
  112. color_ = x > 0 and y > 0 ? #55bd5e
  113. : x > 0 and y < 0 ? #bd9155
  114. : x < 0 and y < 0 ? #bd5c55
  115. : x < 0 and y > 0 ? #557bbd : na
  116.  
  117. // The Ehler Loop
  118. EhlerLoop(y, x, color, len_tail, barScale, offset)
  119.  
  120. // Labels
  121. labels(100, 0.75, "π™Άπš›πš˜πš πš’πš—πš", #55bd5e)
  122. labels(-100, 0.75, "πš†πšŽπšŠπš”πšŽπš—πš’πš—πš", #bd9155)
  123. labels(100, -0.85, "πšπšŽπšŒπš˜πšŸπšŽπš›πš’", #557bbd)
  124. labels(-100, -0.85, "π™²πš˜πš—πšπš›πšŠπšŒπšπš’πš˜πš—", #bd5c55)
  125. labels(0, 1.1, "πšπš˜πšπšŠπšπš’πš˜πš— π™²πš’πšŒπš•πšŽπšœ π™Άπš›πšŠπš™πš‘", #a3a7a8, size.large)
  126.  
  127. if barstate.islast
  128. label.new(bar_index, x, "β¦Ώ 𝙓", style = label.style_label_center, color = #00000000,
  129. textcolor = color.orange, size = size.small)
  130. label.new(bar_index, y, "β¦Ώ 𝙔", style = label.style_label_center, color = #00000000,
  131. textcolor = color.blue, size = size.small)
  132.  
  133. // Table
  134. var tbl = table.new(position.bottom_center, 10, 10, border_color = color.gray, border_width = 1)
  135. table.cell(tbl, 0, 0, 'πš†πšŽπšŠπš”πšŽπš—πš’πš—πš', text_color = x > 0 and y < 0 ? color.orange : color.gray,
  136. text_size = x > 0 and y < 0 ? size.large : size.normal)
  137. table.cell(tbl, 1, 0, 'π™Άπš›πš˜πš πš’πš—πš', text_color = x > 0 and y > 0 ? color.green : color.gray,
  138. text_size = x > 0 and y > 0 ? size.large : size.normal)
  139. table.cell(tbl, 0, 1, 'π™²πš˜πš—πšπš›πšŠπšŒπšπš’πš˜πš—', text_color = x < 0 and y < 0 ? color.red : color.gray,
  140. text_size = x < 0 and y < 0 ? size.large : size.normal)
  141. table.cell(tbl, 1, 1, 'πšπšŽπšŒπš˜πšŸπšŽπš›πš’', text_color = x < 0 and y > 0 ? color.rgb(63, 149, 219) : color.gray,
  142. text_size = x < 0 and y > 0 ? size.large : size.normal)
  143.  
  144. // Bar color
  145. barcolor(showbarcolor ? color_ : na)
  146.  
  147. // X and Y plots
  148. plot(x, color = #ba7c45), plot(y, color = #4583ba)
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement