Fixed offset Vwap

Yusef007

New member
Hello,
Does anyone know how to code a fixed offset VWAP? The one currently available only allows the upper and lower bands to be based off of standard deviations.
Thanks!
 

tradebyday

Active member
I’m looking for a fixed offset where I can displace the upper/lower band by a fixed dollar amount. For instance, the upper band would be $x above the VWAP.
An error you would run into with this method would be that each ticker moves at different rates, so it would only be usable on certain stocks at a time and would NEED to be adjusted for each stock you want to pull up on your chart, which would be a waste of time to be honest. Similar to what @Playstation said I guess you could make it a 5% or a 10% offset in the bands to make it a tad more reliable on multiple tickers with little need to adjust, or set a multiplier X * ATR away from VWAP to use. The second would have similar to a bollinger band-esque style to it which would be kinda cool i guess. These would be my suggestions to make a more universal indicator with little need to tweak from asset to asset
 

johntermotto

New member
2019 Donor
Could you please share the script? I cannot use the link. Thanks

Here is the script:

Code:
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = getAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
    periodIndx = yyyyMmDd;
case WEEK:
    periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
    periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand = price + numDevUp;
plot LowerBand = price + numDevDn;

VWAP.setDefaultColor(getColor(0));
UpperBand.setDefaultColor(getColor(2));
LowerBand.setDefaultColor(getColor(4));
 

Similar threads

Top