TradingView
liquid-trader
21 יוני 2023 06:40

Anchored VWAP (Auto High & Low) 

Invesco QQQ Trust, Series 1NASDAQ

תיאור

OVERVIEW
This script plots, and auto-updates, 3 separate VWAPs: a traditional VWAP, a VWAP anchored to a trends high, and another anchored to a trends low.

VWAP and Anchored VWAPs are commonly used by institutions responsible for the majority of market volume on a given day. Citadel Trading, for example, accounts for approximately 35% of all U.S. listed retail volume, largely executed through program trades over the course of a day, week, or month.

Because VWAP is a prominent market maker tool for executing large trades, day traders can use it to better anticipate trends, mean reversion, and breakouts.

This is most useful on charts with intraday time frames (1 minute, 5 minute etc.) commonly used for day trading. This is not ideal for larger time frames (1 hour or greater) commonly used for swing trading or identifying larger trends.

INPUTS
You can configure:
  • The size, color, and visibility of 6 different plots (VWAP, High Anchor, Low Anchor, Average of Anchors, Quarter Values, Interim Bands)
  • How smooth the average displays


INSPIRATION
1. "How To Measure Anything" by Douglas W. Hubbard
2. "Maximum Trading Gains With Anchored VWAP" by Brian Shannon

Better understanding probability and how to analyze risk (first book), as well as the tools market makers use (second book), has completely reframed how I approach day trading.

הערות שחרור

Minor cleanup.

הערות שחרור

Updated chart.

הערות שחרור

• Improved the scripts color management.
• Minor logic iteration to the "moveCont" function.

הערות שחרור

• Separated the band visibility from the anchor visibility for more control over what displays.

הערות שחרור

• Removed the 1/8 plot prices from displaying to declutter the timescale.

הערות שחרור

• Inputs were set to not display in the status line, minimizing chart clutter.

הערות שחרור

Visual cleanup of settings panel.

הערות שחרור

• Added option to specify when a given anchor should be reset if its VWAP has not been broken, measured in sessions. Disabling this feature allows anchors to run indefinitely if they are not broken. Anchors are reset independently of each other. The feature is enabled and set to "1" by default (aka. the way it used to exclusively work).
• Added option to limit anchor resets to only regular trading hours and new sessions, effectively ignoring AVWAP price breaks during the after hours, overnight, and premarket.

הערות שחרור

• Tooltip corrections.

הערות שחרור

• Removed unnecessary var declarations to reduce performance penalties.
• Added ability to have VWAP continuation for up to 3 days.

הערות שחרור

• Updated script to have the new 2 and 3 day VWAPs turned off by default.

הערות שחרור

• Updated VWAP continuation logic.

הערות שחרור

• Fixed anchor continuation bug.

הערות שחרור

Bug Fix: After a TradingView update, the plots did not work as expected. This release patches the indicator to reinstate the intended functionality of plots.

הערות שחרור

Updating indicator preview. No code changes.
תגובות
Sagittaire7
This is a great script. Would you be able to add a 2-day and 3-day AVWAP as per Brian's book? Maybe it would be easy to start a normal daily VWAP and have it reset at the completion of the next session. Something like that?
liquid-trader
@Sagittaire7, Glad you like it! I'll see what I can do.
Sagittaire7
@liquid-trader, awesome, thanks. I feel like there's a way with checking session.isfirstbar and adding one day to the current time, or maybe storing the timestamp of session.isfirstbar into an array or something like that. But I haven't been able to nail down how exactly yet. Would love to automate these VWAPs.
liquid-trader
@Sagittaire7, The current plan (subject to change) is adding a way to disable the anchors from resetting every new session (session.isfirstbar), ignore premarket reset triggers, and force a reset if it hasn't happened within "x" number of sessions. Off the top of my head, there may also need to be a way to ignore anchor resets during regular trading hours … but let's see how the aforementioned revisions play out and we can navigate from there.
Sagittaire7
@liquid-trader, awesome! I recently finished Brian's book which was mind-blowing. Looking forward to anything you can come up with!
liquid-trader
@Sagittaire7, Wish granted.
Sagittaire7
@liquid-trader, The update is fantastic, I can see so many interactions on day +1/2 now. Thank you so much. Would you be willing to do the same for standard daily VWAP (hlc3)? I'd love to also have daily VWAP +1 day and VWAP +2 days as plots.
liquid-trader
@Sagittaire7, I don't think adding more plots and using longer durations with "ta.vwap()" will produce what you're looking for. One plot would reset daily, and the second would reset every other day. I think you're looking for alternating VWAPs, where every other day a new VWAP is anchored to the new day, extends forward a set number of days, and then expires.

I wish I could make this iterative, putting the plot in loop that iterates through however many days you specify. Unfortunately, this isn't possible in Pine Script, so I wrote something that will simulate this behavior for up to 3 days. Enjoy.
Sagittaire7
@liquid-trader, yeah I wish ta.vwap anchor resets weren't so restrictive. I highly appreciate it. The 2nd and 3rd day VWAPs you made are what I'm looking for, the only thing I noticed is they begin to deviate slightly from a manually-placed one. For example, drop a manual AVWAP on Sunday at 6pm session open on ES1!, by Tuesday around mid-day you can see it begin to deviate from the 2-day VWAP. Any thoughts? Maybe it's due to the small gap between sessions/handoff logic?
liquid-trader
@Sagittaire7, I have no special insight into how "ta.vwap()" calculates the VWAP. My best guess is that it grabs price / volume from a lower timeframe, where as the approximation in this script grabs the last price and volume of the bar. I can play around and see if I can reverse engineer something that gets closer to the built in function. It would be good if they aligned better.
עוד