xmd79

Support and Resistance

Jan 5th, 2023
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 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. // © faytterro
  3.  
  4. //@version=5
  5. indicator("Support and Resistance", overlay = true, max_bars_back =1000)
  6. len=input.int(75, "new zones transp")
  7. len2=input.int(85, "old zones transp")
  8. r = high<low[2]-(high[2]-low[2])
  9. and math.abs(close[1]-open[1])>(high[2]-low[2])*2
  10. r2 = high<math.min(low[3],low[4])-(math.max(high[3],high[4])-math.min(low[3],low[4]))
  11. and math.abs(close[1]-open[2])>(math.max(high[3],high[4])-math.min(low[3],low[4]))*2
  12. for i=1 to 4
  13. r2:= r2 and r2[i]==false
  14. r:= r and r2[i-1]==false
  15. s= low>high[2]-(high[2]-low[2])
  16. and math.abs(close[1]-open[1])>(high[2]-low[2])*2
  17. s2 = low>math.max(high[3],high[4])+(math.max(high[3],high[4])-math.min(low[3],low[4]))
  18. and math.abs(close[1]-open[2])>(math.max(high[3],high[4])-math.min(low[3],low[4]))*2
  19. for i=1 to 4
  20. s2 := s2 and s2[i]==false
  21. s:= s and s2[i-1]==false
  22. ass= ta.crossover(close,high[ta.barssince(r)+2])
  23. for i = 1 to ta.barssince(r)
  24. ass:= ass and ass[i]==false
  25. k=ta.barssince(ass)<ta.barssince(r)? ta.barssince(ass) : -2
  26. box=box.new(last_bar_index-ta.barssince(r)-2,high[ta.barssince(r)+2],
  27. last_bar_index-k,low[ta.barssince(r)+2], bgcolor = color.rgb(255,0,0,80), border_color = color.rgb(71, 89, 139,100))
  28. box.delete(box[1])
  29.  
  30. bass= ta.crossunder(close,high[ta.barssince(r)+2])
  31. for i = 1 to ta.barssince(r)
  32. bass:= bass and bass[i]==false
  33. bk=ta.barssince(bass)<ta.barssince(r)? ta.barssince(bass) : -2
  34. bbox=box.new(last_bar_index-k,high[ta.barssince(r)+2],
  35. last_bar_index-bk,low[ta.barssince(r)+2], bgcolor = color.rgb(0,255,0,80), border_color = color.rgb(71, 89, 139,100))
  36. box.delete(bbox[1])
  37.  
  38.  
  39. ass2= ta.crossover(close,math.max(high[ta.barssince(r2)+3], high[ta.barssince(r2)+4]))
  40. for i = 1 to ta.barssince(r2)
  41. ass2:= ass2 and ass2[i]==false
  42. k2=ta.barssince(ass2)<ta.barssince(r2)? ta.barssince(ass2) : -2
  43. box2=box.new(last_bar_index-ta.barssince(r2)-4,
  44. math.max(high[ta.barssince(r2)+3], high[ta.barssince(r2)+4]),
  45. last_bar_index-k2,
  46. math.min(low[ta.barssince(r2)+3], low[ta.barssince(r2)+4]),
  47. bgcolor = color.rgb(255,0,0,len), border_color = color.rgb(71, 89, 139,100))
  48. box.delete(box2[1])
  49.  
  50. bass2= ta.crossunder(close,math.max(high[ta.barssince(r2)+3], high[ta.barssince(r2)+4]))
  51. for i = 1 to ta.barssince(r2)
  52. bass2:= bass2 and bass2[i]==false
  53. bk2=ta.barssince(bass2)<ta.barssince(r2)? ta.barssince(bass2) : -2
  54. bbox2=box.new(last_bar_index-k2,
  55. math.max(high[ta.barssince(r2)+3], high[ta.barssince(r2)+4]),
  56. last_bar_index-bk2,
  57. math.min(low[ta.barssince(r2)+3], low[ta.barssince(r2)+4]),
  58. bgcolor = color.rgb(0,255,0,len), border_color = color.rgb(71, 89, 139,100))
  59. box.delete(bbox2[1])
  60.  
  61. akk = ta.crossunder(close,low[ta.barssince(s)+2])
  62. for i=1 to ta.barssince(s)
  63. akk:= akk and akk[i]==false
  64. k4=ta.barssince(akk)<ta.barssince(s)? ta.barssince(akk) : -2
  65. box4=box.new(last_bar_index-ta.barssince(s)-2,
  66. high[ta.barssince(s)+2],
  67. last_bar_index-k4,
  68. low[ta.barssince(s)+2],
  69. bgcolor = color.rgb(0,255,0,len), border_color = color.rgb(71, 89, 139,100))
  70. box.delete(box4[1])
  71.  
  72. bakk = ta.crossover(close,low[ta.barssince(s)+2])
  73. for i=1 to ta.barssince(s)
  74. bakk:= bakk and bakk[i]==false
  75. bk4=ta.barssince(bakk)<ta.barssince(s)? ta.barssince(bakk) : -2
  76. bbox4=box.new(last_bar_index-k4,
  77. high[ta.barssince(s)+2],
  78. last_bar_index-bk4,
  79. low[ta.barssince(s)+2],
  80. bgcolor = color.rgb(255,0,0,len), border_color = color.rgb(71, 89, 139,100))
  81. box.delete(bbox4[1])
  82.  
  83. akk2 = ta.crossunder(close,math.min(low[ta.barssince(s2)+3],low[ta.barssince(s2)+4]))
  84. for i=1 to ta.barssince(s2)
  85. akk2:= akk2 and akk2[i]==false
  86. k5=ta.barssince(akk2)<ta.barssince(s2)? ta.barssince(akk2) : -2
  87. box5=box.new(last_bar_index-ta.barssince(s2)-2-2,
  88. math.max(high[ta.barssince(s2)+3],high[ta.barssince(s2)+4]),
  89. last_bar_index-k5,
  90. math.min(low[ta.barssince(s2)+3],low[ta.barssince(s2)+4]),
  91. bgcolor = color.rgb(0,255,0,len), border_color = color.rgb(71, 89, 139,100))
  92. box.delete(box5[1])
  93.  
  94. bakk2 = ta.crossover(close,math.min(low[ta.barssince(s2)+3],low[ta.barssince(s2)+4]))
  95. for i=1 to ta.barssince(s2)
  96. bakk2:= bakk2 and bakk2[i]==false
  97. bk5=ta.barssince(bakk2)<ta.barssince(s2)? ta.barssince(bakk2) : -2
  98. bbox5=box.new(last_bar_index-k5,
  99. math.max(high[ta.barssince(s2)+3],high[ta.barssince(s2)+4]),
  100. last_bar_index-bk5,
  101. math.min(low[ta.barssince(s2)+3],low[ta.barssince(s2)+4]),
  102. bgcolor = color.rgb(255,0,0,len), border_color = color.rgb(71, 89, 139,100))
  103. box.delete(bbox5[1])
  104.  
  105. obox = box.new(last_bar_index-ta.barssince(r)-2-ta.barssince(r)[ta.barssince(r)+1]-1,
  106. high[ta.barssince(r)+2+ta.barssince(r)[ta.barssince(r)+1]+1],
  107. last_bar_index-k[ta.barssince(r)+1]-ta.barssince(r)-2+1,
  108. low[ta.barssince(r)+2+ta.barssince(r)[ta.barssince(r)+1]+1], bgcolor = color.rgb(255,0,0,len2), border_color = color.rgb(1,1,1,100))
  109. box.delete(obox[1])
  110.  
  111. bobox = box.new(last_bar_index-k[ta.barssince(r)+1]-ta.barssince(r)-2+1,
  112. high[ta.barssince(r)+2+ta.barssince(r)[ta.barssince(r)+1]+1],
  113. last_bar_index-bk[ta.barssince(r)+1]-ta.barssince(r)-2+1,
  114. low[ta.barssince(r)+2+ta.barssince(r)[ta.barssince(r)+1]+1], bgcolor = color.rgb(0,255,0,len2), border_color = color.rgb(1,1,1,100))
  115. box.delete(bobox[1])
  116.  
  117. obox2 = box.new(last_bar_index-ta.barssince(r2)-4-ta.barssince(r2)[ta.barssince(r2)+1]-1,
  118. math.max(high[ta.barssince(r2)+3+ta.barssince(r2)[ta.barssince(r2)+1]+1], high[ta.barssince(r2)+4+ta.barssince(r2)[ta.barssince(r2)+1]+1]),
  119. last_bar_index-k2[ta.barssince(r2)+1]-ta.barssince(r2)-4+1+1,
  120. math.min(low[ta.barssince(r2)+3+ta.barssince(r2)[ta.barssince(r2)+1]+1], low[ta.barssince(r2)+4+ta.barssince(r2)[ta.barssince(r2)+1]+1]),
  121. bgcolor = color.rgb(255,0,0,len2), border_color = color.rgb(71, 89, 139,100))
  122. box.delete(obox2[1])
  123.  
  124. bobox2 = box.new(last_bar_index-k2[ta.barssince(r2)+1]-ta.barssince(r2)-4+1+1,
  125. math.max(high[ta.barssince(r2)+3+ta.barssince(r2)[ta.barssince(r2)+1]+1], high[ta.barssince(r2)+4+ta.barssince(r2)[ta.barssince(r2)+1]+1]),
  126. last_bar_index-bk2[ta.barssince(r2)+1]-ta.barssince(r2)-4+1+1,
  127. math.min(low[ta.barssince(r2)+3+ta.barssince(r2)[ta.barssince(r2)+1]+1], low[ta.barssince(r2)+4+ta.barssince(r2)[ta.barssince(r2)+1]+1]),
  128. bgcolor = color.rgb(0,255,0,len2), border_color = color.rgb(71, 89, 139,100))
  129. box.delete(bobox2[1])
  130.  
  131. obox3 = box.new(last_bar_index-ta.barssince(s)-2-ta.barssince(s)[ta.barssince(s)+1]-1,
  132. high[ta.barssince(s)+2+ta.barssince(s)[ta.barssince(s)+1]+1],
  133. last_bar_index-k4[ta.barssince(s)+1]-ta.barssince(s)-2+1,
  134. low[ta.barssince(s)+2+ta.barssince(s)[ta.barssince(s)+1]+1],
  135. bgcolor = color.rgb(0,255,0,len2), border_color = color.rgb(71, 89, 139,100))
  136. box.delete(obox3[1])
  137.  
  138. bobox3 = box.new(last_bar_index-k4[ta.barssince(s)+1]-ta.barssince(s)-2+1,
  139. high[ta.barssince(s)+2+ta.barssince(s)[ta.barssince(s)+1]+1],
  140. last_bar_index-bk4[ta.barssince(s)+1]-ta.barssince(s)-2+1,
  141. low[ta.barssince(s)+2+ta.barssince(s)[ta.barssince(s)+1]+1],
  142. bgcolor = color.rgb(255,0,0,len2), border_color = color.rgb(71, 89, 139,100))
  143. box.delete(bobox3[1])
  144.  
  145. obox4 = box.new(last_bar_index-ta.barssince(s2)-4-ta.barssince(s2)[ta.barssince(s2)+1]-1,
  146. math.max(high[ta.barssince(s2)+3+ta.barssince(s2)[ta.barssince(s2)+1]+1], high[ta.barssince(s2)+4+ta.barssince(s2)[ta.barssince(s2)+1]+1]),
  147. last_bar_index-k5[ta.barssince(s2)+1]-ta.barssince(s2)-4+1,
  148. math.min(low[ta.barssince(s2)+3+ta.barssince(s2)[ta.barssince(s2)+1]+1], low[ta.barssince(s2)+4+ta.barssince(s2)[ta.barssince(s2)+1]+1]),
  149. bgcolor = color.rgb(0,255,0,len2), border_color = color.rgb(71, 89, 139,100))
  150. box.delete(obox4[1])
  151.  
  152. bobox4 = box.new(last_bar_index-k5[ta.barssince(s2)+1]-ta.barssince(s2)-4+1,
  153. math.max(high[ta.barssince(s2)+3+ta.barssince(s2)[ta.barssince(s2)+1]+1], high[ta.barssince(s2)+4+ta.barssince(s2)[ta.barssince(s2)+1]+1]),
  154. last_bar_index-bk5[ta.barssince(s2)+1]-ta.barssince(s2)-4+1,
  155. math.min(low[ta.barssince(s2)+3+ta.barssince(s2)[ta.barssince(s2)+1]+1], low[ta.barssince(s2)+4+ta.barssince(s2)[ta.barssince(s2)+1]+1]),
  156. bgcolor = color.rgb(255,0,0,len2), border_color = color.rgb(71, 89, 139,100))
  157. box.delete(bobox4[1])
  158.  
  159.  
  160.  
Advertisement
Add Comment
Please, Sign In to add comment