Advertisement
xmd79

Gann medians MA targets with Vol weighted

Nov 19th, 2024 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. //@version=5
  2. indicator("Gaann medians MA targets", overlay=true, max_bars_back=500, max_lines_count=500, max_labels_count=500)
  3.  
  4. // Inputs
  5. method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  6. length1 = input(56)
  7. mult1 = input.int(1, minval=0, maxval=1)
  8.  
  9. method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  10. length2 = input(100)
  11. mult2 = input.int(1, minval=0, maxval=1)
  12.  
  13. method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  14. length3 = input(200)
  15. mult3 = input.int(1, minval=0, maxval=1)
  16.  
  17. // Calculation of medians
  18. Avg(x, length, method) =>
  19. sma_1 = ta.sma(x, length)
  20. ema_1 = ta.ema(x, length)
  21. percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
  22. method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
  23.  
  24. a1 = ta.highest(length1) - math.max(close, open)
  25. b1 = math.min(close, open) - ta.lowest(length1)
  26. c1 = math.max(close, open) + a1 * mult1
  27. d1 = math.min(close, open) - b1 * mult1
  28.  
  29. a2 = ta.highest(length2) - math.max(close, open)
  30. b2 = math.min(close, open) - ta.lowest(length2)
  31. c2 = math.max(close, open) + a2 * mult2
  32. d2 = math.min(close, open) - b2 * mult2
  33.  
  34. a3 = ta.highest(length3) - math.max(close, open)
  35. b3 = math.min(close, open) - ta.lowest(length3)
  36. c3 = math.max(close, open) + a3 * mult3
  37. d3 = math.min(close, open) - b3 * mult3
  38.  
  39. // Calculation of volume
  40. volLength = input.int(20, minval=1, title='Volume Length')
  41. volMultiplier = input.float(1.0, title='Volume Multiplier')
  42.  
  43. volAvg = ta.sma(volume, volLength) * volMultiplier
  44.  
  45. // Calculation of signals and liquidity levels
  46. e1 = Avg(c1, length1, method1)
  47. f1 = Avg(d1, length1, method1)
  48. gx1 = 0
  49. cross_1 = ta.cross(close, f1)
  50. gx1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(gx1[1])
  51.  
  52. e2 = Avg(c2, length2, method2)
  53. f2 = Avg(d2, length2, method2)
  54. gx2 = 0
  55. cross_2 = ta.cross(close, f2)
  56. gx2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(gx2[1])
  57.  
  58. e3 = Avg(c3, length3, method3)
  59. f3 = Avg(d3, length3, method3)
  60. gx3 = 0
  61. cross_3 = ta.cross(close, f3)
  62. gx3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(gx3[1])
  63.  
  64. // Calculation of liquidity levels with volume
  65. hilo1 = gx1 * f1 + (1 - gx1) * e1
  66. css1 = gx1 == 1 ? color.green : color.red
  67. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  68.  
  69. hilo2 = gx2 * f2 + (1 - gx2) * e2
  70. css2 = gx2 == 1 ? color.green : color.red
  71. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  72.  
  73. hilo3 = gx3 * f3 + (1 - gx3) * e3
  74. css3 = gx3 == 1 ? color.green : color.red
  75. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  76.  
  77.  
  78. //end of the code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement