Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="Market Open RVR", shorttitle="Market Open RVR", overlay=true, format=format.volume)
- i_length = input.int(defval=20, title=" Volume Days", minval=1, maxval=200)
- f_add_to_array(_arr, _val) =>
- len = array.size(_arr)
- if (len == i_length) // We hit the lookback period
- array.pop(_arr) // Remove the last element
- array.unshift(_arr, _val) // Insert to first position
- else // Still days to go
- array.unshift(_arr, _val)
- // Find if it is a new session
- is_new_sesion = ta.change(time("1D"))
- bgcolor(is_new_sesion ? color.new(color.blue, 85) : na)
- // Arrays for total volume
- var vol_arr_5 = array.new_float(i_length, 0)
- var vol_arr_15 = array.new_float(i_length, 0)
- var vol_arr_30 = array.new_float(i_length, 0)
- var vol_arr_60 = array.new_float(i_length, 0)
- var vol_arr_90 = array.new_float(i_length, 0)
- // Variables for volume
- var int bar_cnt = 0
- var float vol_5 = 0
- var float vol_15 = 0
- var float vol_30 = 0
- var float vol_60 = 0
- var float vol_90 = 0
- // If it's a new session, start over
- // If we have some bars to go, add the volume to current count
- // If we are beyond the target number of bars, keep the last value
- vol_5 := is_new_sesion ? volume : (bar_cnt < 5) ? vol_5 + volume : vol_5
- vol_15 := is_new_sesion ? volume : (bar_cnt < 15) ? vol_5 + volume : vol_15
- vol_30 := is_new_sesion ? volume : (bar_cnt < 30) ? vol_5 + vol_15 + volume : vol_30
- vol_60 := is_new_sesion ? volume : (bar_cnt < 60) ? vol_5 + vol_15 + vol_30 + volume : vol_60
- vol_90 := is_new_sesion ? volume : (bar_cnt < 60) ? vol_5 + vol_15 + vol_30 + vol_60 + volume : vol_90
- bar_cnt := is_new_sesion ? 0 : bar_cnt + 1
- if (bar_cnt == 5)
- f_add_to_array(vol_arr_5, vol_5)
- if (bar_cnt == 15)
- f_add_to_array(vol_arr_15, vol_15)
- if (bar_cnt == 30)
- f_add_to_array(vol_arr_30, vol_30)
- if (bar_cnt == 60)
- f_add_to_array(vol_arr_60, vol_60)
- else if (bar_cnt == 90)
- f_add_to_array(vol_arr_90, vol_90)
- total_volume_5 = array.sum(vol_arr_5)
- avg_volume_5 = array.avg(vol_arr_5)
- total_volume_15 = array.sum(vol_arr_15)
- avg_volume_15 = array.avg(vol_arr_15)
- total_volume_30 = array.sum(vol_arr_30)
- avg_volume_30 = array.avg(vol_arr_30)
- total_volume_60 = array.sum(vol_arr_60)
- avg_volume_60 = array.avg(vol_arr_60)
- total_volume_90 = array.sum(vol_arr_90)
- avg_volume_90 = array.avg(vol_arr_90)
- var string GP2 = "Table Style"
- i_tbl_bg_color = input.color(defval=color.rgb(149, 152, 161, 0), title=" Table Background Color", group=GP2) // rgb(149,152,161)
- 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)
- 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)
- i_tbl_frame_width = input.int(defval=2, title=" Table Frame Width", minval=1, maxval=20, group=GP2)
- i_tbl_border_width = input.int(defval=1, title=" Table Border Width", minval=1, maxval=20, group=GP2)
- string i_tableYpos = input.string(defval="bottom", title=" Table Position", inline="11", options=["top", "middle", "bottom"], group=GP2)
- string i_tableXpos = input.string(defval="right", title="", inline="11", options=["left", "center", "right"], group=GP2)
- // Display table only on last bar to reduce computation time
- if barstate.islast
- // Only Display table on daily chart or a lower timeframe
- if timeframe.isminutes and timeframe.multiplier < 60
- // Create a table with 3 columns and 2 rows
- 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)
- // Populate cells in table
- // Column 1
- table.cell(volTable, 0, 0, text=" ", text_halign=text.align_left)
- table.cell(volTable, 0, 1, text="Volume (Avg)", text_halign=text.align_left)
- table.cell(volTable, 0, 2, text="Volume (Today)", text_halign=text.align_left)
- table.cell(volTable, 0, 3, text="Volume (Today %)", text_halign=text.align_left)
- // Column 2
- table.cell(volTable, 1, 0, text="5m")
- table.cell(volTable, 1, 1, str.tostring(avg_volume_5, format.volume))
- table.cell(volTable, 1, 2, str.tostring(vol_5, format.volume))
- table.cell(volTable, 1, 3, str.tostring(math.round(vol_5 / avg_volume_5 * 100,0)) + "%")
- // Column 3
- table.cell(volTable, 2, 0, text="15m")
- table.cell(volTable, 2, 1, str.tostring(avg_volume_15, format.volume))
- table.cell(volTable, 2, 2, str.tostring(vol_15, format.volume))
- table.cell(volTable, 2, 3, str.tostring(math.round(vol_15 / avg_volume_15 * 100,0)) + "%")
- // Column 4
- table.cell(volTable, 3, 0, text="30m")
- table.cell(volTable, 3, 1, str.tostring(avg_volume_30, format.volume))
- table.cell(volTable, 3, 2, str.tostring(vol_30, format.volume))
- table.cell(volTable, 3, 3, str.tostring(math.round(vol_30 / avg_volume_30 * 100,0)) + "%")
- // Column 5
- table.cell(volTable, 4, 0, text="1hr")
- table.cell(volTable, 4, 1, str.tostring(avg_volume_60, format.volume))
- table.cell(volTable, 4, 2, str.tostring(vol_60, format.volume))
- table.cell(volTable, 4, 3, str.tostring(math.round(vol_60 / avg_volume_60 * 100,0)) + "%")
- // Column 6
- table.cell(volTable, 5, 0, text="90m")
- table.cell(volTable, 5, 1, str.tostring(avg_volume_90, format.volume))
- table.cell(volTable, 5, 2, str.tostring(vol_90, format.volume))
- 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