xmd79

Range Volume Change

May 25th, 2023
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. // This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
  2. // © dman103
  3. //@version=5
  4. // I was looking for a way to see if today's premarket volume is higher or lower than the previous day's premarket, did not find any, hence, I made my own in which I share with you now.
  5. // I call it 'Range Volume Change' or just RVC.
  6. // RVC will show the percentage of change between the selected time range and the previous day for the same time range. As an extra feature, it will also show the volume percentage of change outside the time range (can be disabled from settings).
  7. // This will allow us to see if the volume is increasing or decreasing today compare to the previous day in this specific time range.
  8. // Can be used for various things, like checking premarket volume compare to the previous day or checking specific time range of your interest to see if volume is increasing or decreasing compare to the previous day.
  9. // Also, RVC visualizes the incremental of the volume using increasing size columns giving you a better view of how the volume changes compared to the past.
  10. // in addition, RVC is also designed to work on real-time data.
  11. // Follow for more top indicators/strategies: https://www.tradingview.com/u/dman103/#published-scripts
  12.  
  13.  
  14. indicator('Range Volume Change', 'RVC', overlay=false)
  15. time_range_input = input.session('0400-0930', 'Time Range',tooltip="The time range to show the volume percentage of change between current day time range and previous day for the same time range.")
  16. show_volume_range_between_time_range= input.bool(false,'Show volume change between time range',tooltip="In addtion to the volume on the time range, it will also display volume percetnage of change OUTSIDE the time range.")
  17. val_sun = input(true, title="Sunday",group="Days of week")
  18. val_mon = input(true, title="Monday",group="Days of week")
  19. val_tue = input(true, title="Tuesday",group="Days of week")
  20. val_wed = input(true, title="Wednesday",group="Days of week")
  21. val_thu = input(true, title="Thursday",group="Days of week")
  22. val_fri = input(true, title="Friday",group="Days of week")
  23. val_sat = input(true, title="Saturday",group="Days of week")
  24. var string val_num_sun = val_sun ? '1' : na
  25. var string val_num_mon = val_mon ? '2' : na
  26. var string val_num_tue = val_tue ? '3' : na
  27. var string val_num_wed = val_wed ? '4' : na
  28. var string val_num_thu = val_thu ? '5' : na
  29. var string val_num_fri = val_fri ? '6' : na
  30. var string val_num_sat = val_sat ? '7' : na
  31. time_days = val_num_sun+val_num_mon+val_num_tue+val_num_wed+val_num_thu+val_num_fri+val_num_sat
  32. is_week_day = dayofweek == dayofweek.sunday and val_sun ? true : dayofweek == dayofweek.monday and val_mon ? true : dayofweek == dayofweek.tuesday and val_tue ? true : dayofweek == dayofweek.wednesday and val_wed ? true :
  33. dayofweek == dayofweek.wednesday and val_wed ? true : dayofweek == dayofweek.thursday and val_thu ? true : dayofweek == dayofweek.friday and val_fri ? true : dayofweek == dayofweek.saturday and val_sat ? true : false
  34. is_last_bar_of_day = is_week_day[1] and is_week_day==false
  35.  
  36. is_time_range = time(timeframe.period, time_range_input + ':'+time_days)//,timzone_offset)
  37. tf = is_time_range ? 1 : 0 //1 in time range
  38. varip pre_volume = volume
  39. varip pre_v2 = volume
  40. varip pre_v3 = volume
  41. varip session_volume = 0.
  42. varip session_v2 = volume
  43. varip session_v3 = volume
  44. varip ses_vol = volume
  45. varip last_vol = 0.
  46. if barstate.isnew and barstate.isrealtime
  47. last_vol := volume
  48. else
  49. //////Calculations////////
  50. //Sumup volume in time range
  51. pre_volume := tf > tf[1] or is_last_bar_of_day ? volume : tf == 1 and barstate.isrealtime ? pre_volume + volume - last_vol : barstate.ishistory and tf == 1 ? pre_volume + volume : pre_volume
  52. //sumup volume not in time range
  53. session_volume := tf < tf[1] or is_last_bar_of_day ? volume : tf == 0 and barstate.isrealtime ? session_volume + volume - last_vol : barstate.ishistory and tf == 0 ? session_volume + volume : session_volume
  54. session_v2 := (tf > tf[1] or is_last_bar_of_day) or (barstate.islast and barstate.isrealtime == false) ? session_volume[1] : session_v2
  55. session_v3 := tf > tf[1] or is_last_bar_of_day? session_v2[1] : session_v3
  56. //Time range ends, happens only once per day.
  57. pre_v2 := (tf < tf[1] or is_last_bar_of_day) or (barstate.islast and barstate.isrealtime == false) ? pre_volume[1] : pre_v2
  58. //Time range ends, Takes the previous time range volume to calculate later the percentage, happens only once per day.
  59. pre_v3 := tf < tf[1] or is_last_bar_of_day ? pre_v2[1] : pre_v3
  60. last_vol := volume
  61. plot(is_week_day ? pre_volume : na, style=plot.style_columns, color=tf == 1 ? color.new(color.blue, 25) : na)
  62. plot(show_volume_range_between_time_range and is_week_day ? session_volume : na , style=plot.style_columns, color=tf == 0 ? color.new(color.purple, 25) : na)
  63. //Time range
  64. chg1 = (pre_v2 / pre_v3 - 1) * 100
  65. chg_premarket = (pre_volume / pre_v2[1] - 1) * 100
  66. //Outside time range
  67. chg2 = (session_v2 / session_v3 - 1) * 100
  68. chg_session = (session_volume / session_v2[1] - 1) * 100
  69. var label lbl1 = na
  70. var label lbl2 = na
  71. //History Label
  72. if ((tf < tf[1] ) or (barstate.islast and barstate.isrealtime == false and (tf == 1)) and (is_week_day or is_last_bar_of_day))
  73. lbl1 := label.new(bar_index, pre_volume[is_last_bar_of_day ? 1 : 0], size=size.normal, style=label.style_none, text=str.tostring(chg1, format.mintick) + ' %', textcolor=color.blue)
  74. //Real time label
  75. if barstate.isrealtime and (tf == 1) and (is_week_day or is_last_bar_of_day)
  76. lbl2 := label.new(bar_index, pre_volume[is_last_bar_of_day ? 1 : 0], size=size.normal, style=label.style_none, text=str.tostring(chg_premarket, format.mintick) + ' %', textcolor=color.blue)
  77. label.delete(lbl2[1])
  78. //History Label
  79. if ((tf > tf[1] or is_last_bar_of_day) or (barstate.islast and barstate.isrealtime == false and tf == 0 )) and show_volume_range_between_time_range and (is_week_day or is_last_bar_of_day) and chg2!=0
  80. lbl1 := label.new(bar_index, session_volume[is_last_bar_of_day ? 1 : 0], size=size.normal, style=label.style_none, text=str.tostring(chg2, format.mintick) + ' %', textcolor=color.purple)
  81. //Real time label
  82. if barstate.isrealtime and (tf == 0 ) and show_volume_range_between_time_range and (is_week_day or is_last_bar_of_day) //premarket time
  83. lbl2 := label.new(bar_index, session_volume[is_last_bar_of_day ? 1 : 0], size=size.normal, style=label.style_none, text=str.tostring(chg_session, format.mintick) + ' %', textcolor=color.purple)
  84. label.delete(lbl2[1])
  85.  
Advertisement
Add Comment
Please, Sign In to add comment