Function Pine脚本-时间范围较短的增量卷

Function Pine脚本-时间范围较短的增量卷,function,volume,pine-script,indicator,Function,Volume,Pine Script,Indicator,我有Tradingview的增量音量指示器代码。它在较短的时间段(5分钟)收集卷数据,以获得较高的时间段安全图表。除了最后一个安全条外,这似乎还可以。在这里,5分钟的时间间隔与体积数据完全不正常,显示无意义。 有什么想法吗?这是Pine脚本中的问题吗 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ //@version=4

我有Tradingview的增量音量指示器代码。它在较短的时间段(5分钟)收集卷数据,以获得较高的时间段安全图表。除了最后一个安全条外,这似乎还可以。在这里,5分钟的时间间隔与体积数据完全不正常,显示无意义。 有什么想法吗?这是Pine脚本中的问题吗

// This source code is subject to the terms of the Mozilla Public License 2.0 at 
https://mozilla.org/MPL/2.0/
//@version=4

study(title="Volume Delta", shorttitle="Volume Delta", precision=2)
size = input(title="Fragment Size (minutes)", type=input.integer, defval=5, maxval=1440, minval=1)
// Comment: make sure you have set a large (default) fragment size before switching to a monthly 
chart
var string res = tostring(size)

periodMultiplier = security(syminfo.tickerid, timeframe.period, timeframe.multiplier)
periodIsIntraday = security(syminfo.tickerid, timeframe.period, timeframe.isintraday)
periodIsDaily = security(syminfo.tickerid, timeframe.period, timeframe.isdaily)
periodIsWeekly = security(syminfo.tickerid, timeframe.period, timeframe.isweekly)

int conversion = periodIsIntraday ? 1 : periodIsDaily ? 24 * 60 : periodIsWeekly ? 24 * 60 * 7 : 0
int count = barstate.islast ? floor((timenow - time)/(1000 * 60 * size)) + 1 : conversion * 
periodMultiplier / size

// variable to add or substract volume when computing delta volume
float tickVol = close > open ? volume : close < open ? -volume : 0.0

// function to compute delta volume, max and min delta volume and total delta volume
Vol() =>
    float deltaVol = 0.0
    float totalDeltaVol = 0.0
    float maxDeltaVol = 0.0
    float minDeltaVol = 0.0
    int temp = 0
    temp := count
    for i = 0 to temp - 1
        deltaVol := deltaVol + nz(tickVol[i])
        totalDeltaVol := totalDeltaVol + nz(abs(tickVol[i]))
        if deltaVol > maxDeltaVol
            maxDeltaVol := deltaVol
        if deltaVol < minDeltaVol
            minDeltaVol := deltaVol
    [deltaVol, maxDeltaVol, minDeltaVol, totalDeltaVol]

// calling security with lower timeframe resolution to compute up and down volume more accurately
[deltaVolume, maxDeltaVolume, minDeltaVolume, totalDeltaVolume] = security(syminfo.tickerid, res, 
Vol(), lookahead=barmerge.lookahead_off)

// plotting delta volume bars
hline(0)
plot(deltaVolume, title="Delta Volume", style=plot.style_line, color=color.yellow, transp=65, 
offset=0)
//plot(totalDeltaVolume, title="Total Delta Volume", style=plot.style_line, color=color.blue, 
transp=65, offset=0)
//plot(maxDeltaVolume, title="Max Delta Volume", style=plot.style_line, color=color.green, transp=65, 
offset=0)
//plot(minDeltaVolume, title="Min Delta Volume", style=plot.style_line, color=color.red, transp=65, 
offset=0)
//plot(tickVol, title="Tick Volume", style=plot.style_line, color=color.fuchsia, transp=65, offset=0)

// computing cumulative delta volume
var float cumDeltaVolume = 0.0
cumDeltaVolume := cumDeltaVolume == 0.0 ? deltaVolume : nz(cumDeltaVolume[1]) + deltaVolume
//plot(cumDeltaVolume, title="Cumulative Delta Volume", style=plot.style_line, color=color.orange, 
transp=0, offset=0, linewidth=2)

// computing ohlc values to plot cumulative delta candles
var float o = 0.0
var float c = 0.0
o := cumDeltaVolume == deltaVolume ? 0.0 : c[1]
c := o + deltaVolume
float h = c + maxDeltaVolume - deltaVolume
float l = o + minDeltaVolume

// plotting cumulative delta volume candles
plotcandle(o <= c ? o : na, h, l, c, title="Cumulative Delta Green Candle", color = color.teal, 
wickcolor=color.teal, bordercolor=color.teal)
plotcandle(o >= c ? o : na, h, l, c, title="Cumulative Delta Red Candle", color = color.red, 
wickcolor=color.red, bordercolor=color.red)
//此源代码受Mozilla公共许可证2.0的条款约束,位于
https://mozilla.org/MPL/2.0/
//@版本=4
研究(title=“体积增量”,shorttitle=“体积增量”,精度=2)
size=input(title=“片段大小(分钟)”,type=input.integer,deffal=5,maxval=1440,minval=1)
//备注:在切换到每月一次之前,请确保已设置了较大(默认)的片段大小
图表
变量字符串res=tostring(大小)
period乘数=安全性(syminfo.tickerid、timeframe.period、timeframe.multiplier)
periodIsIntraday=安全性(syminfo.tickerid、timeframe.period、timeframe.isintraday)
periodIsDaily=安全性(syminfo.tickerid,timeframe.period,timeframe.isdaily)
periodIsWeekly=安全性(syminfo.tickerid、timeframe.period、timeframe.isweekly)
整数转换=周期初始值?1:周期是每天吗?24*60:周期是每周吗?24 * 60 * 7 : 0
int count=barstate.islast?地板((timenow-time)/(1000*60*尺寸))+1:转换*
周期乘数/大小
//计算增量体积时添加或减少体积的变量
float tickVol=关闭>打开?音量:关闭<打开-数量:0.0
//用于计算增量体积、最大和最小增量体积以及总增量体积的函数
Vol()=>
浮动增量=0.0
浮动总增量=0.0
浮点maxDeltaVol=0.0
浮点数minDeltaVol=0.0
内部温度=0
温度:=计数
对于i=0至温度-1
deltaVol:=deltaVol+nz(tickVol[i])
totalDeltaVol:=totalDeltaVol+nz(绝对值(滴答量[i]))
如果deltaVol>maxDeltaVol
maxDeltaVol:=deltaVol
如果deltaVol
是的,这是预期的行为。实时条中的条内线段未对齐。请参阅intrabar TFs上使用
security()
的限制。它没有得到电视的官方支持

披露:此答案中的链接指向PineCoders常见问题解答条目。
我是PineCoders社区的成员,很可能是我写的FAQ条目。PineCoders是一个由TradingView支持的志愿者组织,PineCoders的网站是严格的教育网站。TradingView和PineCoders都不能从发送到PineCoders.com的流量中获得经济利益,并且该网站不包含附属/推荐链接