xmd79

Wicked Good S&R Zones

Nov 5th, 2022
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. // Hello tradeurs, ChasinAlts here with a script you've DEFINITELY never seen before. Hope everyone is well. Ok, so heres the low-down...When a wick's
  2. // % size is abvoe the threshold set by the user it is plotted with light blue (these aren't really the significant ones) and are put into an array.
  3. // These large wick lines are great S&R lines but we're looking to filter out to only the best ones. So, after all the large wicks are recorded for the
  4. // chart and lines drawn, it then calculates the area between each of these lines in % (you can think of the lines as the upper and lower lines to a box
  5. // if youd like...ie. it is one of the ways to view the final BEST S&R lines). What we are want is the largest of ALL the % areas between lines and to
  6. // use these as our ultimate S&R Areas. Depending on the Min % Wick size that is chosen, you will find price usually either bouncing between these levels or
  7. // that price will keep bouncing off of the same level until a large spike (up or down) occurs in price and the price will finally breach the level its been
  8. // testing over and over. Once this DOES occur the level that was just broken many times will be the furthest point back for the retest. Now, as stated
  9. // before there are 2 ways to view the output data. Either way it will show the largest % area between the lines as it is developing down the line of
  10. // progressing bars on the chart (that means it WILL change but usually a portion of the previous area/box will be used for the newer smaller box or that
  11. // the area/box will jump back and forth between the same few areas every now and again). Viewing it as a box will show the updated largest box
  12. // (as stated twice now) but viewing it in it's S&R Line form will draw a new S&R line at the top and bottom of where the box would be if it was selected
  13. // EXCEPT that these lines will persist across bars and you will continuously see how these levels will continue to be revisted and constantly used
  14. // as S&R Lines as time progresses. (SO box only show the largest area and lines draws line at the top and bottom of box and persists across bars).
  15. // There is not repainting that can occur. I hope you all enjoy this as I've found it EXTREMELY beneficial bc it's rare that when price first gets to a
  16. // printed S&R level that it wil shooot through it so you can depend on it bouncing off the the levels often multiple times. I've included comments in all
  17. // of the code for your convenience. Also, the higher subscription plan you have (thus the more bars/data you have access to...the more S&R Lines will be drawn).
  18. // Wish you all the best in your endevors and may the force be with your trades, and as ALWAYS...peace and love people....peace and love. ChasinAlts out.
  19.  
  20. //@version=5
  21. indicator("Wicked Good S&R Zones", overlay=true, max_lines_count=500)
  22.  
  23. wkPmin = input.float(2.5, step=.25, title="Minimum (%) Wick Size to use as Line")
  24. draw = input.string("Boxes", title="Draw Support & Resistance _____", options=["Boxes", "Lines"])
  25. showLines = input.bool(true, title="Show Large Wick Lines?"), tooltip="These are not the 'Wicked Good S&R Lines' but rather the lines that derive thems"
  26. wickLnCol = input.color(color.new(#0095ff,75), title="Large Wicks Line Color")
  27. boxCol = input.color(color.new(#ffff00,60), title="Supp & Res Box Color")
  28.  
  29. //== FUNCTIONS ==\\
  30. f_SuppReme_Wick_lines(_open,_high,_low,_close,_time,_timeclose) =>
  31.  
  32. //== FUNCTION INITIALIZATIONS ==\\
  33. var allLnArr=array.new_float(0), topArr=array.new_float(0), botArr=array.new_float(0), diffArr=array.new_float(0), diffCopy=array.new_float(0), var SnRarr=array.new_float(0), var SnRLinesArr=array.new_line(0), var boxArr=array.new_box(0), var bx=box(na), var bot=0.0, var top=0.0
  34.  
  35. //== MAIN LOGIC ==\\
  36. grn = _close > _open
  37. red = _close < _open
  38. uw = (math.abs(_high-(grn?_close:_open))/_close)*100 >= wkPmin // upper and lower wick size calculations
  39. lw = (math.abs((red?_close:_open)-_low)/_close)*100 >= wkPmin // upper and lower wick size calculations
  40. hilo = uw ? _high : _low
  41. if uw or lw
  42. array.push(allLnArr, hilo) // pushes wicks above the % size threshold into an array
  43. if showLines // If user selects to view all Large Wick Lines...
  44. line.new(_time[1], hilo, _time, hilo,
  45. xloc = xloc.bar_time,
  46. extend = extend.right,
  47. color = wickLnCol,
  48. style = line.style_solid) // Plots all lines in array for visualization
  49.  
  50. array.sort(allLnArr,order.ascending) // Sorts all lines in array by price
  51. if array.size(allLnArr)>0
  52. for [i,val] in allLnArr // This 'for...in' loop creates a sort of fake box with upper/lower boundaries being the lines in array that were sorted to get size between each set of lines in array
  53. top := bot, array.push(topArr,top)
  54. bot := val, array.push(botArr,bot)
  55. array.push(diffArr, ((top-bot)/bot)*100) // This line specifically gets the size of the area (in %) between all the lines in the array
  56.  
  57. diffCopy := array.copy(diffArr) // Creates copy of % Size between Lines Array to sort
  58. array.sort(diffCopy,order.ascending) // Sorts % Size Arr
  59. idx = array.indexof(diffArr,array.get(diffCopy,0)) // uses the first entry in the Sorted Area Size(in %) Array to get the index of the Upper/Lower Lines (that belong to the Largest % Area) from the original Line Array in the beginning of script
  60. Top = array.get(topArr,idx) // Gets top line in Arr and...
  61. Bot = array.get(botArr,idx) // Gets bottom line in Arr and...
  62.  
  63. if draw=="Lines" // View S&R Lines
  64. if not array.includes(SnRarr,Top) // Tests if S&R Arr already includes the line
  65. array.push(SnRarr,Top) // If not, pushes it into S&R Arr for end result
  66. array.push(SnRLinesArr, line.new(_time[1], Top, _time, Top,
  67. xloc = xloc.bar_time,
  68. extend = extend.right,
  69. color = _close>=Top ? #00FF00 : #FF0000,
  70. style = line.style_solid)) // Plots line if not already included in Arr
  71.  
  72. if not array.includes(SnRarr,Bot) // Tests if S&R Arr already includes the line
  73. array.push(SnRarr,Bot) // If not, pushes it into S&R Arr for end result
  74. array.push(SnRLinesArr, line.new(_time[1], Bot, _time, Bot,
  75. xloc = xloc.bar_time,
  76. extend = extend.right,
  77. color = _close<=Bot ? #FF0000 : #00FF00,
  78. style = line.style_solid)) // Plots line if not already included in Arr
  79.  
  80. for ln in SnRLinesArr
  81. line.set_color(ln, _close>=line.get_y2(ln) ? #00FF00 : #FF0000) // Changes S&R Lines Color to be green if below price and red if above price
  82.  
  83. if draw=="Boxes" // To view S&R Box
  84. box.set_right(bx,time) // Extends current box to current bar
  85. if Top!=Top[1] or Bot!=Bot[1]
  86. bx := box.new(time[1], Top, time, Bot,
  87. border_color = boxCol,
  88. bgcolor = boxCol,
  89. border_style = line.style_solid,
  90. extend = extend.none,
  91. xloc = xloc.bar_time) // Plots new Box if the Largest % Gap between lines changes (if the largest box on the chart changes)
  92. array.unshift(boxArr,bx)
  93.  
  94.  
  95. f_SuppReme_Wick_lines(open,high,low,close,time,time_close) // Call to Main Function(created a function for this to use in a "Market Overview" Scanner much like many of my other scripts)
  96.  
Advertisement
Add Comment
Please, Sign In to add comment