xmd79

Volume Profile & 2 EMA

Oct 7th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1.  
  2. //This code is not mine this volume profile is by @kv4coins all the contributions for him, i just add 2 emas that TradingLatino uses
  3. //edited by LupownTrader
  4. //@version=4
  5. ///////////////////////////////////////////////////////////////////////////////////////////////////
  6. //// STUDY
  7. ///////////////////////////////////////////////////////////////////////////////////////////////////
  8. study(title = "Volume Profile & 2 EMA",
  9. shorttitle = "VP & EMA's",
  10. overlay = true,
  11. precision = 4,
  12. linktoseries = true,
  13. max_bars_back = 1000,
  14. max_lines_count = 500)
  15.  
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////
  17. //// INPUTS
  18. ///////////////////////////////////////////////////////////////////////////////////////////////////
  19. vp_lookback = input(defval = 200,
  20. title = "Volume Lookback Depth/ Velas atras [10-1000]",
  21. type = input.integer,
  22. minval = 10,
  23. maxval = 1000)
  24.  
  25. vp_max_bars = input(defval = 500,
  26. title = "Number of Bars / ancho [10-500]",
  27. type = input.integer,
  28. minval = 10,
  29. maxval = 500)
  30.  
  31. vp_bar_mult = input(defval = 50,
  32. title = "Bar Length Multiplier / largo [10-100]",
  33. type = input.integer,
  34. minval = 10,
  35. maxval = 100)
  36.  
  37. vp_bar_offset = input(defval = 50,
  38. title = "Bar Horizontal Offset / Distancia con grafico [0-100]",
  39. type = input.integer,
  40. minval = 0,
  41. maxval = 100)
  42.  
  43. vp_bar_width = input(defval = 2,
  44. title = "Bar Width / ancho [1-20]",
  45. type = input.integer,
  46. minval = 1,
  47. maxval = 20)
  48.  
  49. // As suggested by @NXT2017
  50. vp_delta_type = input(defval = "Both",
  51. title = "Delta Type",
  52. type = input.string,
  53. options = ['Both', 'Bullish', 'Bearish'])
  54.  
  55. vp_poc_show = input(defval = true,
  56. title = "Show POC Line",
  57. type = input.bool)
  58.  
  59. vp_bar_color = input(defval = color.new(#9ac8db, 60) ,
  60. title = "Bar Color",
  61. type = input.color)
  62.  
  63. vp_poc_color = input(defval = color.new(color.white, 10),
  64. title = "POC Color",
  65. type = input.color)
  66.  
  67.  
  68. ///////////////////////////////////////////////////////////////////////////////////////////////////
  69. //// VARIABLES
  70. ///////////////////////////////////////////////////////////////////////////////////////////////////
  71. float vp_Vmax = 0.0
  72. int vp_VmaxId = 0
  73. int vp_N_BARS = vp_max_bars
  74.  
  75. var int vp_first = time
  76.  
  77. vp_a_P = array.new_float((vp_N_BARS + 1), 0.0)
  78. vp_a_V = array.new_float(vp_N_BARS, 0.0)
  79. vp_a_D = array.new_float(vp_N_BARS, 0.0)
  80. vp_a_W = array.new_int(vp_N_BARS, 0)
  81.  
  82. ///////////////////////////////////////////////////////////////////////////////////////////////////
  83. //// CALCULATIONS
  84. ///////////////////////////////////////////////////////////////////////////////////////////////////
  85. float vp_HH = highest(high, vp_lookback)
  86. float vp_LL = lowest(low, vp_lookback)
  87.  
  88. if barstate.islast
  89. float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
  90. for j = 1 to (vp_N_BARS + 1)
  91. array.set(vp_a_P, (j-1), (vp_LL + vp_HL * j))
  92. for i = 0 to (vp_lookback - 1)
  93. int Dc = 0
  94. array.fill(vp_a_D, 0.0)
  95. for j = 0 to (vp_N_BARS - 1)
  96. float Pj = array.get(vp_a_P, j)
  97. if low[i] < Pj and high[i] > Pj and (vp_delta_type == "Bullish" ?
  98. close[i] >= open[i] : (vp_delta_type == "Bearish" ? close[i] <= open[i] : true))
  99. float Dj = array.get(vp_a_D, j)
  100. float dDj = Dj + nz(volume[i])
  101. array.set(vp_a_D, j, dDj)
  102. Dc := Dc + 1
  103. for j = 0 to (vp_N_BARS - 1)
  104. float Vj = array.get(vp_a_V, j)
  105. float Dj = array.get(vp_a_D, j)
  106. float dVj = Vj + ((Dc > 0) ? (Dj / Dc) : 0.0)
  107. array.set(vp_a_V, j, dVj)
  108. vp_Vmax := array.max(vp_a_V)
  109. vp_VmaxId := array.indexof(vp_a_V, vp_Vmax)
  110. for j = 0 to (vp_N_BARS - 1)
  111. float Vj = array.get(vp_a_V, j)
  112. int Aj = round(vp_bar_mult * Vj / vp_Vmax)
  113. array.set(vp_a_W, j, Aj)
  114.  
  115. ///////////////////////////////////////////////////////////////////////////////////////////////////
  116. //// PLOTING
  117. ///////////////////////////////////////////////////////////////////////////////////////////////////
  118. if barstate.isfirst
  119. vp_first := time
  120. vp_change = change(time)
  121. vp_x_loc = timenow + round(vp_change * vp_bar_offset)
  122.  
  123. f_setup_bar(n) =>
  124. x1 = ((vp_VmaxId == n) and vp_poc_show) ? max(time[vp_lookback], vp_first) :
  125. (timenow + round(vp_change * (vp_bar_offset - array.get(vp_a_W, n))))
  126. ys = array.get(vp_a_P, n)
  127. line.new(x1 = x1,
  128. y1 = ys,
  129. x2 = vp_x_loc,
  130. y2 = ys,
  131. xloc = xloc.bar_time,
  132. extend = extend.none,
  133. color = (vp_VmaxId == n ? vp_poc_color : vp_bar_color),
  134. style = line.style_solid,
  135. width = vp_bar_width)
  136.  
  137. if barstate.islast
  138. for i = 0 to (vp_N_BARS - 1) by 1
  139. f_setup_bar(i)
  140.  
  141. ///////////////////////////////////////////////////////////////////////////////////////////////////
  142. //// END
  143. ///////////////////////////////////////////////////////////////////////////////////////////////////
  144.  
  145.  
  146. // EMAS
  147. EMA1 = input(20, minval=1, title="EMA1")
  148.  
  149. EMA2 = input(55, minval=1, title="EMA2")
  150.  
  151. EMA3 = input(100, minval=1, title="EMA3")
  152.  
  153. EMA4 = input(200, minval=1, title="EMA4")
  154.  
  155. plot(ema(close, EMA1), color=#2962ff, linewidth=1, title = "EMA 1")
  156. plot(ema(close, EMA2), color=#B45F04, linewidth=2, title= "EMA 2")
  157. plot(ema(close, EMA3), color=#fff176, linewidth=2, title = "EMA 3")
  158. plot(ema(close, EMA4), color=#43ff72, linewidth=2, title= "EMA 4")
  159.  
Advertisement
Add Comment
Please, Sign In to add comment