下午,
我正在尝试将以下 V2 VWAP 脚本转换为 V4,但无法理解第 9 行:
vwapsum = iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
完整脚本如下
//@version=2
study("Monthly VWAP", overlay=true)
showPrevVWAP = input(true, type=bool, title="Show Previous VWAP close")
start = security(tickerid, "M", time)
newSession = iff(change(start), 1, 0)
vwapsum = iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
volumesum = iff(newSession, volume, volumesum[1]+volume)
myvwap = vwapsum/volumesum
plot(myvwap, title="VWAP", color=aqua, style=cross)
我目前的尝试:
//@version=4
study("Monthly VWAP", overlay=true)
showPrevVWAP = input(true, type=input.bool, title="Show Previous VWAP close")
start = security(syminfo.tickerid, "M", time)
newSession = iff(change(start), 1, 0)
vwapsum = iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
volumesum = iff(newSession, volume, volumesum[1]+volume)
myvwap = vwapsum/volumesum
plot(myvwap, title="VWAP", color=color.aqua, style=plot.style_cross)
答案 0 :(得分:0)
开始工作
//@version=4
study("Monthly VWAP", overlay=true)
var float vwapsum = na
var float volumesum = na
newSession = change(time('M'))
vwapsum := newSession ? hl2*volume : hl2*volume + vwapsum[1]
volumesum := newSession ? volume : volume + volumesum[1]
myvwap = vwapsum/volumesum
plot(newSession ? na : myvwap , title="VWAP", color=color.aqua, style=plot.style_cross)
从这里提取我所追求的: Declaring self-referencing variable when converting script to V4 breaks charting