Pine script 版本4未声明的标识符,iff

Pine script 版本4未声明的标识符,iff,pine-script,Pine Script,我正在将下面的脚本从v2更新到v4,并将其清除为3个错误: 第30行:未声明的标识符“p” 第31行:未声明的标识符“vol” 第38行:未声明的标识符“Sn” 我不确定如何重新格式化版本4的“iff”以使该脚本再次运行。 有什么建议吗 // Shows the Daily, Weekly, Monthly, Quarterly, and Yearly VWAP. Also // shows the previous closing VWAP, which is usually very nea

我正在将下面的脚本从v2更新到v4,并将其清除为3个错误:

第30行:未声明的标识符“p”

第31行:未声明的标识符“vol”

第38行:未声明的标识符“Sn”

我不确定如何重新格式化版本4的“iff”以使该脚本再次运行。 有什么建议吗

// Shows the Daily, Weekly, Monthly, Quarterly, and Yearly VWAP. Also
// shows the previous closing VWAP, which is usually very near the
// HLC3 standard pivot for the previous time frame. i.e. The previous
// daily VWAP closing price is usually near the current Daily Pivot.
study("Multi-Timeframe VWAP V2", overlay = true)

std1 = input(title = "STDEV 1", defval = 1,type = input.float, step = 0.1)
std2 = input(title = "STDEV 2", defval = 2, type = input.float, step = 0.1)
std3 = input(title = "STDEV 3", defval = 3, type = input.float, step = 0.1)

showStd = input(false, title = "Show STDEV Bands")
showPrev = input(false, title = "Show Previous VWAP")
showPrevBand = input(false, title = "Show Previous STDEV = 1 Bands")
bands = input(title = "STDEV Bands Timeframe (D, W, M, Q, Y)", defval = "D")

startD = security(syminfo.tickerid, "D", time)
startW = security(syminfo.tickerid, "W", time)
startM = security(syminfo.tickerid, "M", time)
startQ = security(syminfo.tickerid, "3M", time)
startY = security(syminfo.tickerid, "12M", time)

newSessionD = iff(change(startD), 1, 0)
newSessionW = iff(change(startW), 1, 0)
newSessionM = iff(change(startM), 1, 0)
newSessionQ = iff(change(startQ), 1, 0)
newSessionY = iff(change(startY), 1, 0)

getVWAP(newSession) =>
    p = iff(newSession, hlc3 * volume, p[1] + hlc3 * volume)
    vol = iff(newSession, volume, vol[1] + volume)
    v = p / vol
    
    // Incremental weighted standard deviation (rolling)
    // http://people.ds.cam.ac.uk/fanf2/hermes/doc/antiforgery/stats.pdf (part 5)
    // x[i] = hlc3[i], w[i] = volume[i], u[i] - v[i]
    
    Sn = iff(newSession, 0, Sn[1] + volume * (hlc3 - v[1]) * (hlc3 - v))
    std = sqrt(Sn / vol)
    
    [v, std]

[vD, stdevD] = getVWAP(newSessionD)
[vW, stdevW] = getVWAP(newSessionW)
[vM, stdevM] = getVWAP(newSessionM)
[vQ, stdevQ] = getVWAP(newSessionQ)
[vY, stdevY] = getVWAP(newSessionY)

谢谢这就是修复。
//@version=4
// Shows the Daily, Weekly, Monthly, Quarterly, and Yearly VWAP. Also
// shows the previous closing VWAP, which is usually very near the
// HLC3 standard pivot for the previous time frame. i.e. The previous
// daily VWAP closing price is usually near the current Daily Pivot.
study("Multi-Timeframe VWAP V2", overlay = true)

std1 = input(title = "STDEV 1", defval = 1,type = input.float, step = 0.1)
std2 = input(title = "STDEV 2", defval = 2, type = input.float, step = 0.1)
std3 = input(title = "STDEV 3", defval = 3, type = input.float, step = 0.1)

showStd = input(false, title = "Show STDEV Bands")
showPrev = input(false, title = "Show Previous VWAP")
showPrevBand = input(false, title = "Show Previous STDEV = 1 Bands")
bands = input(title = "STDEV Bands Timeframe (D, W, M, Q, Y)", defval = "D")

startD = security(syminfo.tickerid, "D", time)
startW = security(syminfo.tickerid, "W", time)
startM = security(syminfo.tickerid, "M", time)
startQ = security(syminfo.tickerid, "3M", time)
startY = security(syminfo.tickerid, "12M", time)

newSessionD = change(startD)
newSessionW = change(startW)
newSessionM = change(startM)
newSessionQ = change(startQ)
newSessionY = change(startY)

getVWAP(newSession) =>
    var float p     = 0
    var float vol   = 0
    var float Sn    = 0
    p   := newSession ? hlc3 * volume : p[1] + hlc3 * volume
    vol := newSession ? volume : vol[1] + volume
    v = p / vol
    
    // Incremental weighted standard deviation (rolling)
    // http://people.ds.cam.ac.uk/fanf2/hermes/doc/antiforgery/stats.pdf (part 5)
    // x[i] = hlc3[i], w[i] = volume[i], u[i] - v[i]
    
    Sn := newSession ? 0 : Sn[1] + volume * (hlc3 - v[1]) * (hlc3 - v)
    std = sqrt(Sn / vol)
    
    [v, std]

[vD, stdevD] = getVWAP(newSessionD)
[vW, stdevW] = getVWAP(newSessionW)
[vM, stdevM] = getVWAP(newSessionM)
[vQ, stdevQ] = getVWAP(newSessionQ)
[vY, stdevY] = getVWAP(newSessionY)

plot(vD, color=color.red)
plot(vW, color=color.green)
plot(vM, color=color.blue)
plot(vQ, color=color.yellow)
plot(vY, color=color.white)