Hi!
I'm trying to build a vwap that can ignore the first bars "under demand".
This is what I have so far:
Apparently, "sum" doesn't like the dynamic "sinceBar" and it fails with "Only constants expected here"
Does anyone have an idea of how to fix this? Or maybe a better approach?
Thanks in advance!
PS: I'm pretty new on Thinkscript world, so I don't know if what I'm asking is very obvious
I'm trying to build a vwap that can ignore the first bars "under demand".
This is what I have so far:
Code:
input ignoreBars = 5;
def sinceBar = barNumber() - ignoreBars;
def priceVolume = close * volume;
def cumulativePriceVolume = sum(priceVolume, sinceBar);
def cumulativeVolume = sum(volume, sinceBar);
def vwapValue = cumulativePriceVolume / cumulativeVolume;
plot vwapPlot = vwapValue;
Apparently, "sum" doesn't like the dynamic "sinceBar" and it fails with "Only constants expected here"
Does anyone have an idea of how to fix this? Or maybe a better approach?
Thanks in advance!
PS: I'm pretty new on Thinkscript world, so I don't know if what I'm asking is very obvious