Current VWAP with current volume

H

HeadSpade

New member
If anyone is willing to help out. I need simple code that will display, current volume*current VWAP.

I copy pasted it something together.

I think it's working.

Can someone have a look at this.

Code:
def V = volume(GetSymbol(), AggregationPeriod.DAY);

def VP = vwap(getSymbol(), AggregationPeriod.DAY);

def money = V*VP;

AddLabel (yes, ("Money: ")+ Round(money * .000001, 1) + "M", Color.CYAN);
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
Try this:

Code:
# Current Volume times Current VWAP Value
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#

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));

def VWAP = price;
def UpperBand = price + numDevUp * deviation;
def LowerBand = price + numDevDn * deviation;
def vol = volume;

def money = vol*VWAP;

AddLabel (yes, ("Money: ")+ Round(money * .000001, 1) + "M", Color.CYAN);
 
H

HeadSpade

New member
Code:
def V = volume(GetSymbol(), AggregationPeriod.DAY);

def VP = vwap(getSymbol(), AggregationPeriod.DAY);

def money = V*VP;

AddLabel (yes, ("Money: ")+ Round(money * .000001, 1) + "M", Color.CYAN);


Hey BenTen, I realize that this is giving me the number that I don't want. Bc it takes VWAP from a Daily chart which is way lagging behind the VWAP from let's say 3min chart. I changed in VWAP to show in min and then it only show on that particular chart, lets say 3min. Which is obvious, but why Still doesn't take the VWAP from the 3min, still the number is not correct.

All I really need is simple number that I track in my data that will show VWAP from 3min chart * Current Day Vol.
That's all. I'd appreciate your help. Thanks!
 
Last edited:

Similar threads

Top