TradingView
kurtsmock
28 mag 2022 02:20

Automated Anchored VWAP 

Bitcoin / TetherUS PERPETUAL CONTRACTBinance

Descrizione

This was reasonably easy to put together and I can't find one that does this in the Library and I've been wanting one. Of course, the drawing tool is just fantastic, but sometimes it can be forgotten as new pivots emerge.

What you'll find elsewhere in the Library is a nice variety of fancier methods for determining an anchor point with labels, lines, timestamps and standard deviations.
This is just a simple script to pull the Anchored VWAP off of the most recent pivot and update that as new pivots become defined.
I wanted it to be really portable so it could easily work into other things you're working on while also keeping the chart reasonably clean.

The way this functions is as follows: A new pivot is found and VWAP is calculated from it. At that point the prior aVWAP is no longer tracked and it picks up from the new pivot .
Of course this means that the plot doesn't generate until the pivot is actually confirmed, which in turn means that the plot doesn't reach back to the pivot , it begins based on whatever "right bars" period you end up choosing.
I kind of like it that way, because you have your eyes on the one that matters until the new one matters.

The downside is that it doesn't track old pivots . The old aVWAP might still be in play. But if you track all of the old one's you'll have a 100 lines on your chart and no one wants that.
I recommend when you look back and think the old one is still in play, use the drawing tool to keep it on the chart.
Otherwise, let the script do the work for you.

Hope its helpful. Let me know what you think should be done to make it better.

Note di rilascio

Small Update. I noticed as using it that it will track a pivot high aVWAP that completely doesn't matter because its been thoroughly broken.
So I added a switch to make that optional. The switch will stop plotting after an aVWAP is broken through.
Typically when these events occur it means one of two things:
1. Price is in a range and aVWAP doesn't matter much at the left/right intervals chosen because participants are getting in positions (accumulating or distributing).
2. (e.g. Pivot High) When price breaks above the pivot high aVWAP and keeps running, those who sold that top are forced to cover their positions and/or chase price up. In such case, their sell from that pivot high makes that aVWAP irrelevant.

Let me know if you see anything else that should be added/changed.
Commenti
UnknownUnicorn15320316
is repaint?
kurtsmock
@Bafrali1453, lol. The repaint question. Love it. Tradingview should put a repaint checkbox for all scripts.

Repainting is not really an issue with pretty much any vwap calculation.

If you're asking about repainting in the context of backtesting and/or replay mode... Backtest and replay will behave exactly the same as a live chart.

There could a slight difference on the bar that confirms the pivot on a live chart because of the way the loop is constructed. But it would be pretty negligible. I'll look at it more closely today.

But just compare it to the drawing tool while trying it out in replay mode or in a backtest. You will get an exact match
kurtsmock
@kurtsmock, Yea. I double checked. It tracks accurately on the the bar that the pivot is confirmed too
allanster
Very nice, thank you for sharing!
Simon14868
Is there a way to add standard deviations?
FolloWoney
//@version=5
indicator("Supertrend VWAP", overlay = true, timeframe = "", timeframe_gaps = true)

atrPeriod = input.int(10, "ATR Length", minval = 1)
factor = input.float(3.0, "Factor", minval = 0.01, step = 0.01)
vwap_period = input.int(14, "VWAP Length", minval = 1)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

vwap = ta.rma(close, vwap_period)

trend_up = (direction < 0) and (close > vwap[1])
trend_down = (direction < 0) and (close < vwap[1])

plot(trend_up ? vwap : na, "Up Trend", color = color.green, style = plot.style_linebr)
plot(trend_down ? vwap : na, "Down Trend", color = color.red, style = plot.style_linebr)
plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
vensonom
Is it possible to show atleast last 3 old pivot’s vwap ?
kurtsmock
@vensonom, Not sure what you mean by "Last 3 old Pivot's"
uttraag
Will u help me for creating this ANCHOR VWAP plotting automatically on previous day High and low and also screener for INTRADAY searching stock for INTRADAY trading...
kurtsmock
@uttraag, I started to play with the idea. Its remarkable how hard it actually is. I can think of a way to do it, but the first method I discerned is not very visually appealing, since you don't know what the prior day's high is until the day is over. Meaning, it doesn't start plotting the prior day high until the new day begins.
Conversely, if you wanted to make it visually appealing and have it drawn from the prior day high across to the next day, you would need to reset it on each new high of the present day, then find a way to carry that vwap anchor through the next day, while tracking the current day to be ready for the day after that. You'd need two rolling aVWAPs.

There's two problems to solve: (a) that you can't know what the high of the day is until the day is over and (b) the script calculates and plots left to right, meaning you can't calculate and plot the vwap on historical bars.

haha. What a trip. I think I know how to do it. But, its kinda crazy how much time it would take to make.
Altro