xmd79

Support/Resistant Zone (Simple)

May 22nd, 2023
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.11 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/Mpivotlow/2.0/
  2. // © TrendCrypto2022
  3.  
  4. //@version=5
  5. indicator('Support/Resistant Zone (Simple)', overlay=true)
  6.  
  7. // Input Pivot
  8. number = input.float(15, "Number bars to detect Pivot High/Low", minval=3, maxval=30, step=1, group='Detect Pivot High/Low')
  9. alert1 = input.bool (title="Alert when price test Support Zone", defval=true, group="Set up Alert")
  10. alert2 = input.bool (title="Alert when price test Resistant Zone", defval=true, group="Set up Alert")
  11.  
  12. //Pivot High/Low and Resistant Zone
  13. // Calculator Pivot High and Resistant Zone
  14. pivothigh = ta.pivothigh(high, number, number)
  15. pivothighv1 = ta.valuewhen(pivothigh, high[number], 0), pivothighb1 = ta.valuewhen(pivothigh, bar_index[number], 0), pivothighv1low = ta.valuewhen(pivothigh, close[number]>open[number] ? close[number] : open[number], 0)
  16. pivothighv2 = ta.valuewhen(pivothigh, high[number], 1), pivothighb2 = ta.valuewhen(pivothigh, bar_index[number], 1), pivothighv2low = ta.valuewhen(pivothigh, close[number]>open[number] ? close[number] : open[number], 1)
  17. pivothighv3 = ta.valuewhen(pivothigh, high[number], 2), pivothighb3 = ta.valuewhen(pivothigh, bar_index[number], 2), pivothighv3low = ta.valuewhen(pivothigh, close[number]>open[number] ? close[number] : open[number], 2)
  18.  
  19. // Draw Resistant Zone
  20. var line linepivothighv1 = na
  21. line.delete(linepivothighv1)
  22. linepivothighv1 := line.new(pivothighb1, pivothighv1, bar_index, pivothighv1, width = 1, color = close > pivothighv1 ? color.lime : color.red)
  23. var line linepivothighv1low = na
  24. line.delete(linepivothighv1low)
  25. linepivothighv1low := line.new(pivothighb1, pivothighv1low, bar_index, pivothighv1low, width = 1, color = close > pivothighv1low ? color.lime : color.red)
  26. linefill.new(linepivothighv1, linepivothighv1low, color = close > math.max(pivothighv1low, pivothighv1) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  27.  
  28. var line linepivothighv2 = na
  29. line.delete(linepivothighv2)
  30. linepivothighv2 := line.new(pivothighb2, pivothighv2, bar_index, pivothighv2, width = 1, color = close > pivothighv2 ? color.lime : color.red)
  31. var line linepivothighv2low = na
  32. line.delete(linepivothighv2low)
  33. linepivothighv2low := line.new(pivothighb2, pivothighv2low, bar_index, pivothighv2low, width = 1, color = close > pivothighv2low ? color.lime : color.red)
  34. linefill.new(linepivothighv2, linepivothighv2low, color = close > math.max(pivothighv2low, pivothighv2) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  35.  
  36. var line linepivothighv3 = na
  37. line.delete(linepivothighv3)
  38. linepivothighv3 := line.new(pivothighb3, pivothighv3, bar_index, pivothighv3, width = 1, color = close > pivothighv3 ? color.lime : color.red)
  39. var line linepivothighv3low = na
  40. line.delete(linepivothighv3low)
  41. linepivothighv3low := line.new(pivothighb3, pivothighv3low, bar_index, pivothighv3low, width = 1, color = close > pivothighv3low ? color.lime : color.red)
  42. linefill.new(linepivothighv3, linepivothighv3low, color = close > math.max(pivothighv3low, pivothighv3) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  43.  
  44.  
  45. // Label Resistant Zone
  46. var label Label_pivothighv1 = na
  47. label.delete(Label_pivothighv1)
  48. Label_pivothighv1 := label.new(x=time + 120, y=pivothighv1, text='' + str.tostring(pivothighv1) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  49.  
  50. var label Label_pivothighv2 = na
  51. label.delete(Label_pivothighv2)
  52. Label_pivothighv2 := label.new(x=time + 120, y=pivothighv2, text='' + str.tostring(pivothighv2) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  53.  
  54. var label Label_pivothighv3 = na
  55. label.delete(Label_pivothighv3)
  56. Label_pivothighv3 := label.new(x=time + 120, y=pivothighv3, text='' + str.tostring(pivothighv3) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  57.  
  58. var label Label_pivothighv1low = na
  59. label.delete(Label_pivothighv1low)
  60. Label_pivothighv1low := label.new(x=time + 120, y=pivothighv1low, text='' + str.tostring(pivothighv1low) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  61.  
  62. var label Label_pivothighv2low = na
  63. label.delete(Label_pivothighv2low)
  64. Label_pivothighv2low := label.new(x=time + 120, y=pivothighv2low, text='' + str.tostring(pivothighv2low) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  65.  
  66. var label Label_pivothighv3low = na
  67. label.delete(Label_pivothighv3low)
  68. Label_pivothighv3low := label.new(x=time + 120, y=pivothighv3low, text='' + str.tostring(pivothighv3low) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  69.  
  70. // Calculator Pivot Low and Support Zone
  71. pivotlow = ta.pivotlow(low, number, number)
  72. pivotlowv1 = ta.valuewhen(pivotlow, low[number], 0), pivotlowb1 = ta.valuewhen(pivotlow, bar_index[number], 0), pivotlowv1high = ta.valuewhen(pivotlow, close[number]>open[number] ? open[number] : close[number], 0)
  73. pivotlowv2 = ta.valuewhen(pivotlow, low[number], 1), pivotlowb2 = ta.valuewhen(pivotlow, bar_index[number], 1), pivotlowv2high = ta.valuewhen(pivotlow, close[number]>open[number] ? open[number] : close[number], 1)
  74. pivotlowv3 = ta.valuewhen(pivotlow, low[number], 2), pivotlowb3 = ta.valuewhen(pivotlow, bar_index[number], 2), pivotlowv3high = ta.valuewhen(pivotlow, close[number]>open[number] ? open[number] : close[number], 2)
  75.  
  76. // Draw Support Zone
  77. var line linepivotlowv1 = na
  78. line.delete(linepivotlowv1)
  79. linepivotlowv1 := line.new(pivotlowb1, pivotlowv1, bar_index, pivotlowv1, width = 1, color = close > pivotlowv1 ? color.lime : color.red)
  80. var line linepivotlowv1high = na
  81. line.delete(linepivotlowv1high)
  82. linepivotlowv1high := line.new(pivotlowb1, pivotlowv1high, bar_index, pivotlowv1high, width = 1, color = close > pivotlowv1high ? color.lime : color.red)
  83. linefill.new(linepivotlowv1, linepivotlowv1high, color = close > math.max(pivotlowv1high, pivotlowv1) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  84.  
  85. var line linepivotlowv2 = na
  86. line.delete(linepivotlowv2)
  87. linepivotlowv2 := line.new(pivotlowb2, pivotlowv2, bar_index, pivotlowv2, width = 1, color = close > pivotlowv2 ? color.lime : color.red)
  88. var line linepivotlowv2high = na
  89. line.delete(linepivotlowv2high)
  90. linepivotlowv2high := line.new(pivotlowb2, pivotlowv2high, bar_index, pivotlowv2high, width = 1, color = close > pivotlowv2high ? color.lime : color.red)
  91. linefill.new(linepivotlowv2, linepivotlowv2high, color = close > math.max(pivotlowv2high, pivotlowv2) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  92.  
  93. var line linepivotlowv3 = na
  94. line.delete(linepivotlowv3)
  95. linepivotlowv3 := line.new(pivotlowb3, pivotlowv3, bar_index, pivotlowv3, width = 1, color = close > pivotlowv3 ? color.lime : color.red)
  96. var line linepivotlowv3high = na
  97. line.delete(linepivotlowv3high)
  98. linepivotlowv3high := line.new(pivotlowb3, pivotlowv3high, bar_index, pivotlowv3high, width = 1, color = close > pivotlowv3high ? color.lime : color.red)
  99. linefill.new(linepivotlowv3, linepivotlowv3high, color = close > math.max(pivotlowv3high, pivotlowv3) ? color.new(color.lime, transp =90) : color.new(color.red, transp =90))
  100.  
  101. // Label Support Zone
  102. var label Label_pivotlowv1 = na
  103. label.delete(Label_pivotlowv1)
  104. Label_pivotlowv1 := label.new(x=time + 120, y=pivotlowv1, text='' + str.tostring(pivotlowv1) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  105.  
  106. var label Label_pivotlowv2 = na
  107. label.delete(Label_pivotlowv2)
  108. Label_pivotlowv2 := label.new(x=time + 120, y=pivotlowv2, text='' + str.tostring(pivotlowv2) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  109.  
  110. var label Label_pivotlowv3 = na
  111. label.delete(Label_pivotlowv3)
  112. Label_pivotlowv3 := label.new(x=time + 120, y=pivotlowv3, text='' + str.tostring(pivotlowv3) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  113.  
  114. var label Label_pivotlowv1high = na
  115. label.delete(Label_pivotlowv1high)
  116. Label_pivotlowv1high := label.new(x=time + 120, y=pivotlowv1high, text='' + str.tostring(pivotlowv1high) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  117.  
  118. var label Label_pivotlowv2high = na
  119. label.delete(Label_pivotlowv2high)
  120. Label_pivotlowv2high := label.new(x=time + 120, y=pivotlowv2high, text='' + str.tostring(pivotlowv2high) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  121.  
  122. var label Label_pivotlowv3high = na
  123. label.delete(Label_pivotlowv3high)
  124. Label_pivotlowv3high := label.new(x=time + 120, y=pivotlowv3high, text='' + str.tostring(pivotlowv3high) + '', color=color.new(#000000, 100), textcolor = color.yellow, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  125.  
  126.  
  127. // Set up alerts when price test Support/Resistant Zone
  128. price_closebefore1 = close[1]
  129.  
  130. // Alert price test Support Zone
  131. _testlong(_x, _y) =>
  132. var int trend = na
  133. trend := price_closebefore1 > math.max(_x,_y) ? 1 : price_closebefore1 < math.min(_x,_y) ? -1 : trend[1]
  134. if trend == 1 and alert1 ==true and low < math.max(_x,_y) and close > math.min(_x,_y)
  135. alert (''+ str.tostring(syminfo.ticker) +' test Support Zone. Price: '+ str.tostring(close) +'.', alert.freq_once_per_bar)
  136.  
  137. _testlong(pivothighv1, pivothighv1low)
  138. _testlong(pivothighv2, pivothighv2low)
  139. _testlong(pivothighv3, pivothighv3low)
  140. _testlong(pivotlowv1, pivotlowv1high)
  141. _testlong(pivotlowv2, pivotlowv2high)
  142. _testlong(pivotlowv3, pivotlowv3high)
  143.  
  144. // Alert price test Resistant Zone
  145. _testshort(_c, _d) =>
  146. var int trendshort = na
  147. trendshort := price_closebefore1 < math.min(_c,_d) ? -1 : price_closebefore1 > math.max(_c,_d) ? 1 : trendshort[1]
  148. if trendshort == -1 and alert1 ==true and high > math.min(_c,_d) and close < math.max(_c,_d)
  149. alert (''+ str.tostring(syminfo.ticker) +' test Resistant Zone. Price: '+ str.tostring(close) +'.', alert.freq_once_per_bar)
  150.  
  151. _testshort(pivothighv1, pivothighv1low)
  152. _testshort(pivothighv2, pivothighv2low)
  153. _testshort(pivothighv3, pivothighv3low)
  154. _testshort(pivotlowv1, pivotlowv1high)
  155. _testshort(pivotlowv2, pivotlowv2high)
  156. _testshort(pivotlowv3, pivotlowv3high)
  157.  
  158.  
  159.  
Advertisement
Add Comment
Please, Sign In to add comment