Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Sorry I meant that the horizontal lines would adjust and move accordingly to the vwap bubbles to the right. Instead of the traditional vwap bands.@Alex You said it yourself, VWAP move throughout the day. It's not static. As a result, you can't display it as a horizontal line.
This would actually be a great ideaCorrect
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));
# 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!
thank you much guys, this community is truly great!@Alex @germanburrito Updated the code above to do exactly what you want. Thanks to @BenTen
Heres the link if you need it
http://tos.mx/cZOtww6
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);
You mean something like this Consecutive Bar Counter?@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
no the settings on the indicator ask for a bar number, to tell what the needed bar number you use a lower indicatorYou mean something like this Consecutive Bar Counter?
https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/
I am not entirely sure what you mean by Bar Counter.....and setting it
ok thank youno 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 lostno the settings on the indicator ask for a bar number, to tell what the needed bar number you use a lower indicator
YOU NEED LOWER INDICATOR THAT TELL YOU WHAT THE NUMBER BAR YOU WANT TO START THE CALCULATION FROM IS HERES IT IS....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
so to change the bar number in the settings of the indicator.....
i understood it to be this.....
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....
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
P | VWAP Deviations Band Scanner | Questions | 2 | |
N | Extend lines from high Relative Vol and Vwap at close script. | Questions | 0 | |
B | convergence / divergence 9ema to VWAP | Questions | 0 | |
B | Anchor VWAP to specific time of day | Questions | 2 | |
M | Anchored VWAP Premarket previous days | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.