首个市场开放的音量表
我目前有这个脚本,可以为今天和最后20天的平均数据提供数量数据。但是,我正在寻找市场开放的前X分钟/小时,我正在寻找平均数量和量的平均值(最近20天)。
示例 :5分钟vol/vol avg基于首先 5分钟的市场开放。在开始前5分钟之后,此单元格停止更新,因为它已经超过了前5分钟。
//@version=5
indicator(title="Data Table RVR", shorttitle="Data Table RVR", overlay=true)
///////////////////////////////////////////////////////////////////////////////// INPUTS
var string GP1 = "Volume"
i_length = input.int(defval=20, title=" Volume Days", minval=1, maxval=200, group=GP1)
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)
///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS
openCurTime(tf) => request.security(syminfo.tickerid, tf, time)
///////////////////////////////////////////////////////////////////////////////// VOLUME DATA
// Current days volume
volToday = request.security(syminfo.tickerid, "D", volume)
volTodaySinceOpen = math.round(request.security(syminfo.tickerid, "5", volume ))
volTodayMil = math.round(volToday / 1000000, 2)
// Average volume over last X days
volXDayAvg = request.security(syminfo.tickerid, "D", ta.sma(volume, i_length))
volXDayAvgMil = math.round(volXDayAvg / 1000000, 2)
// Percent current days volume of average volume
percentVolXDay = math.round(volToday / volXDayAvg * 100, 0)
///////////////////////////////////////////////////////////////////////////////// TABLE
vol1 = math.round(request.security(syminfo.tickerid, "5", volume))
//vol1Avg = math.round(request.security(syminfo.tickerid, "5", ta.sma(volume, i_length)) / 1000000, 2)
vol1Avg = request.security(syminfo.tickerid, "5", ta.sma(volume, i_length))
vol2 = math.round(request.security(syminfo.tickerid, "15", volume))
vol2Avg = request.security(syminfo.tickerid, "15", ta.sma(volume, i_length))
vol3 = math.round(request.security(syminfo.tickerid, "30", volume))
vol3Avg = request.security(syminfo.tickerid, "30", ta.sma(volume, i_length))
vol4 = math.round(request.security(syminfo.tickerid, "60", volume))
vol4Avg = request.security(syminfo.tickerid, "60", ta.sma(volume, i_length))
vol5 = math.round(request.security(syminfo.tickerid, "90", volume))
vol5Avg = request.security(syminfo.tickerid, "90", ta.sma(volume, i_length))
/////////////////////////////////////////////////////////////////////////////////
// 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(vol1Avg, format.volume))
table.cell(volTable, 1, 2, str.tostring(vol1, format.volume))
table.cell(volTable, 1, 3, str.tostring(math.round(vol1 / vol1Avg * 100,0)) + "%")
// Column 3
table.cell(volTable, 2, 0, text="15m")
table.cell(volTable, 2, 1, str.tostring(vol2Avg, format.volume))
table.cell(volTable, 2, 2, str.tostring(vol2, format.volume))
table.cell(volTable, 2, 3, str.tostring(math.round(vol2 / vol2Avg * 100,0)) + "%")
// Column 4
table.cell(volTable, 3, 0, text="30m")
table.cell(volTable, 3, 1, str.tostring(vol3Avg, format.volume))
table.cell(volTable, 3, 2, str.tostring(vol3, format.volume))
table.cell(volTable, 3, 3, str.tostring(math.round(vol3 / vol3Avg * 100,0)) + "%")
// Column 5
table.cell(volTable, 4, 0, text="1hr")
table.cell(volTable, 4, 1, str.tostring(vol4Avg, format.volume))
table.cell(volTable, 4, 2, str.tostring(vol4, format.volume))
table.cell(volTable, 4, 3, str.tostring(math.round(vol4 / vol4Avg * 100,0)) + "%")
// Column 6
table.cell(volTable, 5, 0, text="90m")
table.cell(volTable, 5, 1, str.tostring(vol5Avg, format.volume))
table.cell(volTable, 5, 2, str.tostring(vol5, format.volume))
table.cell(volTable, 5, 3, str.tostring(math.round(vol5 / vol5Avg * 100,0)) + "%")```
I currently have this script that gives me volume data for Today and last 20 days average. But, I am looking for volume and volume average (last 20 days) for only the first x minutes/hour of the market opening.
Example: 5 mins vol/vol avg is based on first 5 mins of the market open. After the first 5 mins, this cell stops updating since it's beyond the first 5 mins.
//@version=5
indicator(title="Data Table RVR", shorttitle="Data Table RVR", overlay=true)
///////////////////////////////////////////////////////////////////////////////// INPUTS
var string GP1 = "Volume"
i_length = input.int(defval=20, title=" Volume Days", minval=1, maxval=200, group=GP1)
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)
///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS
openCurTime(tf) => request.security(syminfo.tickerid, tf, time)
///////////////////////////////////////////////////////////////////////////////// VOLUME DATA
// Current days volume
volToday = request.security(syminfo.tickerid, "D", volume)
volTodaySinceOpen = math.round(request.security(syminfo.tickerid, "5", volume ))
volTodayMil = math.round(volToday / 1000000, 2)
// Average volume over last X days
volXDayAvg = request.security(syminfo.tickerid, "D", ta.sma(volume, i_length))
volXDayAvgMil = math.round(volXDayAvg / 1000000, 2)
// Percent current days volume of average volume
percentVolXDay = math.round(volToday / volXDayAvg * 100, 0)
///////////////////////////////////////////////////////////////////////////////// TABLE
vol1 = math.round(request.security(syminfo.tickerid, "5", volume))
//vol1Avg = math.round(request.security(syminfo.tickerid, "5", ta.sma(volume, i_length)) / 1000000, 2)
vol1Avg = request.security(syminfo.tickerid, "5", ta.sma(volume, i_length))
vol2 = math.round(request.security(syminfo.tickerid, "15", volume))
vol2Avg = request.security(syminfo.tickerid, "15", ta.sma(volume, i_length))
vol3 = math.round(request.security(syminfo.tickerid, "30", volume))
vol3Avg = request.security(syminfo.tickerid, "30", ta.sma(volume, i_length))
vol4 = math.round(request.security(syminfo.tickerid, "60", volume))
vol4Avg = request.security(syminfo.tickerid, "60", ta.sma(volume, i_length))
vol5 = math.round(request.security(syminfo.tickerid, "90", volume))
vol5Avg = request.security(syminfo.tickerid, "90", ta.sma(volume, i_length))
/////////////////////////////////////////////////////////////////////////////////
// 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(vol1Avg, format.volume))
table.cell(volTable, 1, 2, str.tostring(vol1, format.volume))
table.cell(volTable, 1, 3, str.tostring(math.round(vol1 / vol1Avg * 100,0)) + "%")
// Column 3
table.cell(volTable, 2, 0, text="15m")
table.cell(volTable, 2, 1, str.tostring(vol2Avg, format.volume))
table.cell(volTable, 2, 2, str.tostring(vol2, format.volume))
table.cell(volTable, 2, 3, str.tostring(math.round(vol2 / vol2Avg * 100,0)) + "%")
// Column 4
table.cell(volTable, 3, 0, text="30m")
table.cell(volTable, 3, 1, str.tostring(vol3Avg, format.volume))
table.cell(volTable, 3, 2, str.tostring(vol3, format.volume))
table.cell(volTable, 3, 3, str.tostring(math.round(vol3 / vol3Avg * 100,0)) + "%")
// Column 5
table.cell(volTable, 4, 0, text="1hr")
table.cell(volTable, 4, 1, str.tostring(vol4Avg, format.volume))
table.cell(volTable, 4, 2, str.tostring(vol4, format.volume))
table.cell(volTable, 4, 3, str.tostring(math.round(vol4 / vol4Avg * 100,0)) + "%")
// Column 6
table.cell(volTable, 5, 0, text="90m")
table.cell(volTable, 5, 1, str.tostring(vol5Avg, format.volume))
table.cell(volTable, 5, 2, str.tostring(vol5, format.volume))
table.cell(volTable, 5, 3, str.tostring(math.round(vol5 / vol5Avg * 100,0)) + "%")```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,这里有一个 5 分钟和 15 分钟的小例子。
下面的代码是专门为 1 分钟时间范围编写的。如果您需要在不同的时间范围内使用它,则需要进行调整。
您应该使用大小为
交易量天
的数组。这样您的数组将始终包含最近n
天的数据。首先,您应该确定当前柱是否是一个新会话。这对于重置一些变量很有用。
假设您想要获取 5 分钟的体积数据。在 1 分钟时间范围内,这将是 5 个柱。
有一个计数器,用于记录每个会话中的柱数(在新会话时重置)。
如果当前会话柱数小于您的目标(例如 5 分钟/柱),则跟踪交易量
当您达到目标柱数时,将总交易量添加到数组中
这是您可以使用的示例代码。我为你添加了一些评论。如果有不清楚的地方请告诉我。
编辑:
So, here is a small example for 5min and 15min.
Below code is written specifically for the 1min timeframe. If you need to use this on a different timeframe, it needs to be adjusted.
You should use arrays with a size of your
volume days
. This way your array would always have the data of the lastn
days.First of all, you should figure out if the current bar is a new session. This will be useful to reset some variables.
Let's say you want to get 5 min volume data. On the 1min timeframe, this would be 5 bars.
Have a counter for number of bars in each session (reset when it is a new session).
Keep track of the volume if the current session bar number is less than your target (5 min/bars for example)
When you hit your target bar number, add the total volume to your array
This is a sample code which you can use. I have added some comments for you. Let me know if something is unclear.
Edit: