Advertisement
Guest User

Untitled

a guest
Apr 20th, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. //@version=5
  2. indicator(title="Market Open RVR", shorttitle="Market Open RVR", overlay=true, format=format.volume)
  3.  
  4. i_length = input.int(defval=20, title=" Volume Days", minval=1, maxval=200)
  5.  
  6.  
  7. f_add_to_array(_arr, _val) =>
  8. len = array.size(_arr)
  9.  
  10. if (len == i_length) // We hit the lookback period
  11. array.pop(_arr) // Remove the last element
  12. array.unshift(_arr, _val) // Insert to first position
  13. else // Still days to go
  14. array.unshift(_arr, _val)
  15.  
  16. // Find if it is a new session
  17. is_new_sesion = ta.change(time("1D"))
  18. bgcolor(is_new_sesion ? color.new(color.blue, 85) : na)
  19.  
  20. // Arrays for total volume
  21. var vol_arr_5 = array.new_float(i_length, 0)
  22. var vol_arr_15 = array.new_float(i_length, 0)
  23. var vol_arr_30 = array.new_float(i_length, 0)
  24. var vol_arr_60 = array.new_float(i_length, 0)
  25. var vol_arr_90 = array.new_float(i_length, 0)
  26.  
  27. // Variables for volume
  28. var int bar_cnt = 0
  29. var float vol_5 = 0
  30. var float vol_15 = 0
  31. var float vol_30 = 0
  32. var float vol_60 = 0
  33. var float vol_90 = 0
  34.  
  35. // If it's a new session, start over
  36. // If we have some bars to go, add the volume to current count
  37. // If we are beyond the target number of bars, keep the last value
  38. vol_5 := is_new_sesion ? volume : (bar_cnt < 5) ? vol_5 + volume : vol_5
  39. vol_15 := is_new_sesion ? volume : (bar_cnt < 15) ? vol_5 + volume : vol_15
  40. vol_30 := is_new_sesion ? volume : (bar_cnt < 30) ? vol_5 + vol_15 + volume : vol_30
  41. vol_60 := is_new_sesion ? volume : (bar_cnt < 60) ? vol_5 + vol_15 + vol_30 + volume : vol_60
  42. vol_90 := is_new_sesion ? volume : (bar_cnt < 60) ? vol_5 + vol_15 + vol_30 + vol_60 + volume : vol_90
  43.  
  44. bar_cnt := is_new_sesion ? 0 : bar_cnt + 1
  45.  
  46. if (bar_cnt == 5)
  47. f_add_to_array(vol_arr_5, vol_5)
  48. if (bar_cnt == 15)
  49. f_add_to_array(vol_arr_15, vol_15)
  50. if (bar_cnt == 30)
  51. f_add_to_array(vol_arr_30, vol_30)
  52. if (bar_cnt == 60)
  53. f_add_to_array(vol_arr_60, vol_60)
  54. else if (bar_cnt == 90)
  55. f_add_to_array(vol_arr_90, vol_90)
  56.  
  57.  
  58. total_volume_5 = array.sum(vol_arr_5)
  59. avg_volume_5 = array.avg(vol_arr_5)
  60.  
  61. total_volume_15 = array.sum(vol_arr_15)
  62. avg_volume_15 = array.avg(vol_arr_15)
  63.  
  64. total_volume_30 = array.sum(vol_arr_30)
  65. avg_volume_30 = array.avg(vol_arr_30)
  66.  
  67. total_volume_60 = array.sum(vol_arr_60)
  68. avg_volume_60 = array.avg(vol_arr_60)
  69.  
  70. total_volume_90 = array.sum(vol_arr_90)
  71. avg_volume_90 = array.avg(vol_arr_90)
  72.  
  73.  
  74. var string GP2 = "Table Style"
  75. i_tbl_bg_color = input.color(defval=color.rgb(149, 152, 161, 0), title="  Table Background Color", group=GP2) // rgb(149,152,161)
  76. i_tbl_border_color = input.color(defval=color.rgb(30, 39, 46, 0), title="  Table Border Color", group=GP2) // Black Pearl= rgb(30, 39, 46)
  77. i_tbl_text_color = input.color(defval=color.rgb(241, 242, 246, 0), title="  Table Text Color", group=GP2) // Anti-Flash White = rgb(241, 242, 246)
  78. i_tbl_frame_width = input.int(defval=2, title="  Table Frame Width", minval=1, maxval=20, group=GP2)
  79. i_tbl_border_width = input.int(defval=1, title="  Table Border Width", minval=1, maxval=20, group=GP2)
  80.  
  81. string i_tableYpos = input.string(defval="bottom", title=" Table Position", inline="11", options=["top", "middle", "bottom"], group=GP2)
  82. string i_tableXpos = input.string(defval="right", title="", inline="11", options=["left", "center", "right"], group=GP2)
  83.  
  84.  
  85. // Display table only on last bar to reduce computation time
  86. if barstate.islast
  87.  
  88. // Only Display table on daily chart or a lower timeframe
  89. if timeframe.isminutes and timeframe.multiplier < 60
  90. // Create a table with 3 columns and 2 rows
  91. var table volTable = table.new(i_tableYpos + "_" + i_tableXpos, 6, 7, bgcolor = i_tbl_bg_color, frame_width = i_tbl_frame_width, frame_color = i_tbl_border_color, border_width = i_tbl_border_width, border_color = i_tbl_border_color)
  92. // Populate cells in table
  93.  
  94. // Column 1
  95. table.cell(volTable, 0, 0, text=" ", text_halign=text.align_left)
  96. table.cell(volTable, 0, 1, text="Volume (Avg)", text_halign=text.align_left)
  97. table.cell(volTable, 0, 2, text="Volume (Today)", text_halign=text.align_left)
  98. table.cell(volTable, 0, 3, text="Volume (Today %)", text_halign=text.align_left)
  99. // Column 2
  100. table.cell(volTable, 1, 0, text="5m")
  101. table.cell(volTable, 1, 1, str.tostring(avg_volume_5, format.volume))
  102. table.cell(volTable, 1, 2, str.tostring(vol_5, format.volume))
  103. table.cell(volTable, 1, 3, str.tostring(math.round(vol_5 / avg_volume_5 * 100,0)) + "%")
  104. // Column 3
  105. table.cell(volTable, 2, 0, text="15m")
  106. table.cell(volTable, 2, 1, str.tostring(avg_volume_15, format.volume))
  107. table.cell(volTable, 2, 2, str.tostring(vol_15, format.volume))
  108. table.cell(volTable, 2, 3, str.tostring(math.round(vol_15 / avg_volume_15 * 100,0)) + "%")
  109. // Column 4
  110. table.cell(volTable, 3, 0, text="30m")
  111. table.cell(volTable, 3, 1, str.tostring(avg_volume_30, format.volume))
  112. table.cell(volTable, 3, 2, str.tostring(vol_30, format.volume))
  113. table.cell(volTable, 3, 3, str.tostring(math.round(vol_30 / avg_volume_30 * 100,0)) + "%")
  114. // Column 5
  115. table.cell(volTable, 4, 0, text="1hr")
  116. table.cell(volTable, 4, 1, str.tostring(avg_volume_60, format.volume))
  117. table.cell(volTable, 4, 2, str.tostring(vol_60, format.volume))
  118. table.cell(volTable, 4, 3, str.tostring(math.round(vol_60 / avg_volume_60 * 100,0)) + "%")
  119. // Column 6
  120. table.cell(volTable, 5, 0, text="90m")
  121. table.cell(volTable, 5, 1, str.tostring(avg_volume_90, format.volume))
  122. table.cell(volTable, 5, 2, str.tostring(vol_90, format.volume))
  123. table.cell(volTable, 5, 3, str.tostring(math.round(vol_90 / avg_volume_90 * 100,0)) + "%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement