Is there a way to get the a price relative to SD . Example price is @ + 1.3 SD
@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);