AnchorVWAP (Please note. The label for this indicator works only between the anchorbegin and anchorEnd setting).@Goingdar365
That's how it should be working... I have made small changes that suits my trading style. Feel free to use the one that works best for you.
Providing both VWAP and AnchorVWAP in the below.
VWAP
input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.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 UpperBand1 = price + numDevUp1 * deviation;
plot UpperBand2 = price + numDevUp2 * deviation;
plot UpperBand3 = price + numDevUp3 * deviation;
plot LowerBand1 = price + numDevDn1 * deviation;
plot LowerBand2 = price + numDevDn2 * deviation;
plot LowerBand3 = price + numDevDn3 * deviation;
VWAP.setDefaultColor(getColor(0));
UpperBand1.setDefaultColor(getColor(2));
UpperBand2.setDefaultColor(getColor(2));
UpperBand3.setDefaultColor(getColor(2));
LowerBand1.setDefaultColor(getColor(4));
LowerBand2.setDefaultColor(getColor(4));
LowerBand3.setDefaultColor(getColor(4));
input labels = yes;
AddLabel(labels, " ", Color.BLACK);
AddLabel(labels, (if close > LowerBand3 then "[-3]" else "[-3]") + " " + AsText(LowerBand3), if close < LowerBand3 then Color.CYAN else Color.GRAY );
AddLabel(labels, (if close > LowerBand2 then "[-2]" else "[-2]") + " " + AsText(LowerBand2), if close < LowerBand2 then Color.CYAN else Color.LIGHT_GRAY);
AddLabel(labels, (if close > LowerBand1 then "[-1]" else "[-1]") + " " + AsText(LowerBand1), if close < LowerBand1 then Color.CYAN else Color.WHITE);
#AddLabel(labels, " ", Color.BLACK);
AddLabel(labels, (if close > VWAP then "[VWAP]" else "[-VWAP]") + " " + AsText(VWAP), if close > VWAP then Color.GREEN else Color.RED);
#AddLabel(labels, " ", Color.BLACK);
AddLabel(labels, (if close > UpperBand1 then "[1]" else "[1]") + " " + AsText(UpperBand1), if close > UpperBand1 then Color.CYAN else Color.WHITE);
AddLabel(labels, (if close > UpperBand2 then "[2]" else "[2]") + " " + AsText(UpperBand2), if close > UpperBand2 then Color.CYAN else Color.LIGHT_GRAY);
AddLabel(labels, (if close > UpperBand3 then "[3]" else "[3]") + " " + AsText(UpperBand3), if close > UpperBand3 then Color.CYAN else Color.GRAY);
AddLabel(labels, " ", Color.BLACK);
def anchorbegin = 0930;
def anchorEnd = 1630;
input ShowTodayOnly = no;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def rth = SecondsFromTime(anchorbegin) >= 0 and
SecondsTillTime(anchorEnd) >= 0;
def volumeSum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeSum2[1] + volume
else 0;
def volumeVwapSum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeVwapSum2[1] + volume * vwap
else 0;
def volumeVwap2Sum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeVwap2Sum2[1] + volume * Sqr(vwap)
else 0;
def price2 = volumeVwapSum2 / volumeSum2;
def deviation2 = Sqrt(Max(volumeVwap2Sum2 / volumeSum2 - Sqr(price2), 0));
plot anchorVWAP = price2;
anchorVWAP.SetStyle(Curve.FIRM);
anchorVWAP.SetDefaultColor(Color.LIGHT_ORANGE);
anchorVWAP.SetLineWeight(2);
input numDevU1 = 1.0;
input numDevU2 = 2.0;
input numDevU3 = 3.0;
input numDevD1 = -1.0;
input numDevD2 = -2.0;
input numDevD3 = -3.0;
plot UpperLine1 = anchorVWAP + numDevU1 * deviation2;
plot UpperLine2 = anchorVWAP + numDevU2 * deviation2;
plot UpperLine3 = anchorVWAP + numDevU3 * deviation2;
plot LowerLine1 = anchorVWAP + numDevD1 * deviation2;
plot LowerLine2 = anchorVWAP + numDevD2 * deviation2;
plot LowerLine3 = anchorVWAP + numDevD3 * deviation2;
input labelsD = yes;
AddLabel(labelsD, " ", Color.BLACK);
AddLabel(labelsD, (if close > LowerLine3 then "[-3]" else "[-3]") + " " + AsText(LowerLine3), if close < LowerLine3 then Color.CYAN else Color.GRAY);
AddLabel(labelsD, (if close > LowerLine2 then "[-2]" else "[-2]") + " " + AsText(LowerLine2), if close < LowerLine2 then Color.CYAN else Color.LIGHT_GRAY);
AddLabel(labelsD, (if close > LowerLine1 then "[-1]" else "[-1]") + " " + AsText(LowerLine1), if close < LowerLine1 then Color.CYAN else Color.WHITE);
#AddLabel(labelsD, " ", Color.BLACK);
AddLabel(labelsD, (if close > anchorVWAP then "[VWAP]" else "[-VWAP]") + " " + AsText(anchorVWAP), if close > anchorVWAP then Color.GREEN else Color.RED);
#AddLabel(labelsD, " ", Color.BLACK);
AddLabel(labelsD, (if close > UpperLine1 then "[1]" else "[1]") + " " + AsText(UpperLine1), if close > UpperLine1 then Color.CYAN else Color.WHITE);
AddLabel(labelsD, (if close > UpperLine2 then "[2]" else "[2]") + " " + AsText(UpperLine2), if close > UpperLine2 then Color.CYAN else Color.LIGHT_GRAY);
AddLabel(labelsD, (if close > UpperLine3 then "[3]" else "[3]") + " " + AsText(UpperLine3), if close > UpperLine3 then Color.CYAN else Color.GRAY);
AddLabel(labelsD, " ", Color.BLACK);