Как мне получить 8-часовой совокупный TWAP для 1-минутных свечей на Pinescript? - PullRequest
0 голосов
/ 27 мая 2020

Я создаю индикатор, который использует 8-часовой совокупный TWAP для 1-минутных свечей, который будет сбрасываться каждые 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 голосов
/ 28 мая 2020

Вы были близки)

//@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

...