[英]Trying to convert V2 VWAP Script to V4 issues
Afternoon all,整个下午,
I am trying to convert the below V2 VWAP script to V4 but can't get my head around the line 9:我正在尝试将以下 V2 VWAP 脚本转换为 V4,但无法理解第 9 行:
vwapsum = iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
Full script below完整脚本如下
//@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)
My attempt so far:到目前为止我的尝试:
//@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)
Got it working得到它的工作
//@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)
Extracted what I was after from here: Declaring self-referencing variable when converting script to V4 breaks charting从这里提取我想要的内容: Declaring self-referencing variable when convert script to V4 breaks charting
Hey can you elaborate on what happens in this line:嘿,你能详细说明这一行发生了什么:
vwapsum := newSession ? hl2*volume : hl2*volume + vwapsum[1]
what is that + vwapsum[1]
那是什么+ vwapsum[1]
And how is it plotting the way that it does, i mean it takes 1 M or week or whatever, and then restarts?它是如何绘制它的方式的,我的意思是它需要 1 M 或一周或其他什么,然后重新启动? Doesnt that take up the same plotting space?这不占用相同的绘图空间吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.