Advertisement
xmd79

Liquidity Heatmap [HunterAlgos]

Sep 17th, 2023
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © HunterAlgos
  3.  
  4. //@version=5
  5. indicator("Liquidity Heatmap [HunterAlgos]", shorttitle = "Liquidity Heatmap [1.0.0]", overlay = true, max_lines_count = 500, max_bars_back = 500, max_labels_count = 500)
  6.  
  7. long_css = input.color(#26c6da, "Long liquidity color" , group = "COLORS")
  8. short_css = input.color(#ff0000, "Short liquidity color", group = "COLORS")
  9.  
  10. sensibility = input.int (10000, "Opacity value" , tooltip = "Adjust the opacity of the liquidity level manually - (Autopilot off)", group = "SETTINGS")
  11. l_sens = input.int (500 , "Opacity Average", tooltip = "Set the average value of the opacity - Example : 500 set will take the average of 500 bar and 250 bar to determine the average of the liquidity levels", group = "SETTINGS")
  12. leverage = input.float(0.5 , "Leverage" , tooltip = "Example : 0.5 = 100x leverage - 4.5 = 20x leverage", group = "SETTINGS", step = 0.5)
  13. width = input.int (10 , "Width" , group = "SETTINGS")
  14. leverage /= 100
  15.  
  16. auto = input.bool(true, "Autopilot", tooltip = "Determine automatically a decent opacity value" , group = "GENERAL")
  17. show_long = input.bool(true, "Enable long liquidity" , group = "GENERAL")
  18. show_short = input.bool(true, "Enable short liquidity" , group = "GENERAL")
  19. filter = input.bool(true, "Filtering", tooltip = "Long liquidity = only green candle, short liquidity = only down candle", group = "GENERAL")
  20.  
  21.  
  22. data = input.string("nzVolume", options=["nzOI", "OI", "nzVolume", "Volume"], group = "DATA")
  23.  
  24. type bin
  25. float[] v
  26. line [] u
  27. line [] d
  28.  
  29. var z = bin.new(
  30. array.new< float >(1)
  31. , array.new< line >(1)
  32. , array.new< line >(1)
  33. )
  34.  
  35. main = data == "nzOI" ? request.security(str.tostring(syminfo.basecurrency) + "USDT.P_OI","", close - nz(close[1])) : data == "nzVolume" ? volume - nz(volume[1]) : data == "Volume" ? volume : data == "OI" ? math.abs(open - close) : na
  36.  
  37. calc() =>
  38. if z.v.size() > 50000
  39. z.v.shift()
  40. z.v.push(main)
  41.  
  42. size = l_sens
  43. avg = math.avg(ta.highest(main, size), ta.highest(main, size / 2))
  44. round_to = 100
  45. ceil = math.ceil (avg / round_to) * round_to
  46. floor = math.floor(avg / round_to) * round_to
  47. result = math.abs (avg - ceil ) < math.abs(avg - floor) ? ceil : floor
  48.  
  49. _math = auto ? result : sensibility
  50.  
  51. _math
  52.  
  53.  
  54. method gradient(array<float> y, color css) =>
  55. var color id = na
  56. id := color.from_gradient(y.last(), 0, calc(), color.new(color.white, 100), css)
  57. id
  58.  
  59.  
  60. drawLine(x, y, _x, css) =>
  61. var line id = na
  62. id := line.new(x1 = x, y1 = y, x2 = _x, y2 = y, xloc = xloc.bar_index, color = css, width = width)
  63. id
  64.  
  65. method puts(bool mode, array<line> a, line l) =>
  66. if mode == true
  67. if a.size() == 500
  68. line.delete(a.shift())
  69. a.push(l)
  70. if mode == false
  71. for j = a.size() - 1 to 0 by 1
  72. x = line.get_x2(a.get(j))
  73. y = line.get_y1(a.get(j))
  74. if bar_index - 1 == x - 1 and not (high > y and low < y)
  75. line.set_x2(a.get(j), bar_index + 1)
  76.  
  77. filt(bool bull) =>
  78. bool out = false
  79. if bull == true and filter == true
  80. out := close > open ? true : false
  81. if bull == false and filter == true
  82. out := close < open ? true : false
  83.  
  84. if filter == false
  85. out := true
  86.  
  87. out
  88.  
  89. draw() =>
  90. bool up_dot = false
  91. bool dn_dot = false
  92. if show_long and filt(true) == true
  93. line l = na
  94. l := drawLine(bar_index, low * (1 - leverage), bar_index, z.v.gradient(long_css))
  95. true.puts (z.u , l )
  96. up_dot := true
  97. if show_short and filt(false) == true
  98. line l = na
  99. l := drawLine(bar_index, high * (1 + leverage), bar_index, z.v.gradient(short_css))
  100. true.puts(z.d, l)
  101. dn_dot := true
  102.  
  103. [up_dot, dn_dot]
  104.  
  105. [up_dot, dn_dot] = draw()
  106.  
  107.  
  108. false.puts(z.u, na)
  109. false.puts(z.d, na)
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement