• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

VWAP deviations as horizontal lines?

Alex

Member
VIP
Make the vwap and its 2 standard deviations appear as self adjusting extended horizontal lines? would it be possible to make?
 

Alex

Member
VIP
@generic Not quite... As the vwap and the deviations adjust throughout the trading day I'd like them to display as horizontal lines instead of the "typical" vwap. I think its possible...

Standard VWAP:

Screen-Shot-2020-11-17-at-11-14-42-PM.png


what I mean:

Screen-Shot-2020-11-17-at-11-16-30-PM.png
 
Last edited by a moderator:

generic

Active member
@Alex @germanburrito Not exactly what you want but this is the extent of my copy and paste coding skills.

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));
def upper = price + numDevUp * deviation;
def lower = price + numDevDn * deviation;

def currentbar = if !isnan(close) && isnan(close[-1]) then barnumber() else double.nan;
def vwap_line = if barnumber() == currentbar then price else double.nan;
def upper_line = if barnumber() == currentbar then upper else double.nan;
def lower_line = if barnumber() == currentbar then lower else double.nan;

plot VWAP = highestall(vwap_line);
plot UpperBand = highestall(upper_line);
plot LowerBand = highestall(lower_line);

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

BenTen

Administrative
Staff
VIP
Saw this in the OneNote drive:

Code:
# Horizontal Line at current VWAP JQ
# chatroom request for generic
# 2020-11-18

def currentbar = if !isnan(close) && isnan(close[-1]) then barnumber() else double.nan;
def var1 = if barnumber() == currentbar then vwap else double.nan;
plot currentVWAP = highestall(var1);

#plot debug = vwap;
# That's All Folks!
 

germanburrito

Active member
@Soloways With this you can set the bar where you want the count to start from, youre goiont to need a bar counter that goes in the lower study

Code:
declare lower;
plot b = barnumber();
#VM_MIDAS_StandartDeviationBands;
def Data = BarNumber();
input Number_Of_Bar = 1;
input price = close;
def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + price * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = Data - Number_Of_Bar;
def sample = if bar then sample[1] + Sqr(price - vw) else 0;
def var = sample / bars;
def dev = Sqrt(var);

plot dev1 =  vw + dev * 2;
plot dev2 = vw - (dev * 2);
plot dev3 = vw + (dev * 1);
plot devN1 =  vw - dev * 1;


vw.setdefaultColor(color.yellow);
dev1.SetDefaultColor(Color.White);
dev2.SetDefaultColor(Color.White);
dev3.SetDefaultColor(Color.White);
devn1.SetDefaultColor(Color.White);


dev1.Setlineweight(2);
dev2.Setlineweight(2);
dev3.Setlineweight(2);
devn1.Setlineweight(2);
 

Similar threads

Top