我如何在Pinescript上获得1分钟蜡烛的8小时累积TWAP?

时间:2020-05-27 13:47:29

标签: pine-script

我正在创建一个指标,该指标采用1小时蜡烛的8小时累积TWAP,将每8小时重置一次。这应该能够在所有时间范围内显示。这是正确的方法吗?

resIn        = input("480", "Resolution")
res          = resIn == "0" ? '1' : resIn
typicalPrice = ohlc4
weight       = barssince(change(security))
price        = 0.0

price       := weight == 0 ? typicalPrice : typicalPrice + nz(price[1])
twap         = price / (weight + 1)

非常感谢。

1 个答案:

答案 0 :(得分:1)

您很近)

//@version=4
study("8H VWAP")
resIn        = input("480", "Resolution")
typicalPrice = ohlc4
reset        = change(time(resIn))
weight       = barssince(reset)
price        = 0.0

price       := weight == 0 ? typicalPrice : typicalPrice + nz(price[1])
twap         = price / (weight + 1)

plot(twap)
bgcolor(reset ? color.gray : na)

enter image description here