VWAP deviations as horizontal lines?

Alex

Active member
VIP
Make the vwap and its 2 standard deviations appear as self adjusting extended horizontal lines? would it be possible to make?
 
@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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@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:
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!
 
@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);
 
no the settings on the indicator ask for a bar number, to tell what the needed bar number you use a lower indicator
to be honest, i am completely lost
so i loaded your code you put together
and added it to XPEV 30D 1HR chart and this is what i get

Screen-Shot-2020-12-06-at-13-05-58.png


so to change the bar number in the settings of the indicator.....
i understood it to be this.....

Screen-Shot-2020-12-06-at-13-06-50.png



so what number of bars should i enter in order for the my chart to look like the example chart i posted in the beginning
like this....

Screen-Shot-2020-12-05-at-13-31-31.png
 
to be honest, i am completely lost
so i loaded your code you put together
and added it to XPEV 30D 1HR chart and this is what i get

Screen-Shot-2020-12-06-at-13-05-58.png


so to change the bar number in the settings of the indicator.....
i understood it to be this.....

Screen-Shot-2020-12-06-at-13-06-50.png



so what number of bars should i enter in order for the my chart to look like the example chart i posted in the beginning
like this....

Screen-Shot-2020-12-05-at-13-31-31.png
YOU NEED LOWER INDICATOR THAT TELL YOU WHAT THE NUMBER BAR YOU WANT TO START THE CALCULATION FROM IS HERES IT IS....
WHAT YOU DO IS YOU HOVER OVER THE BAR YOU WANT TO START FROM, YOU SEE THE BAR NUMBER AND YOU INPUT IT IN THE VWAP


declare lower;
plot b = barnumber();
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
293 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top