OPEN-SOURCE SCRIPT

ZenAlgo - Levels

201
This script combines multiple anchored Volume-Weighted Average Price (VWAP) calculations into a single tool, providing a continuous record of past VWAP levels and highlighting when price has tested them. Typically, VWAP indicators show only the current VWAP for a single anchor period, requiring you to either keep re-anchoring manually or juggle multiple instances of different VWAP tools for each timeframe. By contrast, this script automatically tracks both the ongoing VWAP and previously completed VWAP values, along with real-time detection of “tests” (when price crosses a particular VWAP level). It’s especially valuable for traders who want to see how price has interacted with VWAP over several sessions, weeks, or months—without switching between separate indicators or manually setting anchors.

Below is a comprehensive explanation of each component, why multiple VWAP lines working together can be more informative than a single line, and how to adjust the script for various markets and trading styles:

  • Primary VWAP vs. Historical VWAP Lines - Standard VWAP indicators typically focus on the current line only. This script also calculates a primary VWAP, but it “locks in” each completed VWAP value when a new time anchor is detected (e.g., new weekly bar, new monthly bar, new session). As a result, you retain an ongoing history of VWAP lines for every completed anchored period. This is more powerful than manually setting up multiple VWAP tools—one for each desired timeframe—because everything is handled in a single script. You avoid chart clutter and the risk of forgetting to reset your manual VWAP at the correct bar.
  • Why Combine Multiple Anchored VWAP Lines in One Script? - Viewing several anchored VWAP lines together offers synergy. You see not only the current VWAP but also previous ones from different sessions or months, all within the same chart pane. This synergy becomes apparent if multiple historical VWAP lines cluster near the same price level, indicating a potentially significant zone of volume-based support or resistance. Handling this manually would involve repeatedly setting separate VWAP indicators, each reset at specific points, which is time-consuming and prone to error. In this script, the process is automated: as soon as the anchor changes, a completed VWAP line is stored so you can observe how price eventually reacts to it, repeatedly or not at all.
  • Automated “Test” Detection - Once a historical VWAP line is set, the script tracks when price crosses it in subsequent bars. If the high and low of a bar span that line, the script marks it in red (both the line and its label). It also keeps a counter of how many times each line has been tested. This method goes beyond a simple visual approach by quantifying the retests. Because all these lines are created and managed in one place, you don’t have to manually label the lines or check them one by one.


Advantages Over Manually Setting Multiple VWAPs
  • You save screen space: Instead of layering several VWAP indicators, each with unique settings, this single script plots them all on one overlay.
  • Automation: When a new anchor period begins, the script “closes out” the old VWAP and starts a new one. You never need to remember to reset it manually.
  • Retest Visualization: The script not only draws each line but also changes color and updates the label automatically if a line gets tested. Doing this by hand would be labor-intensive.
  • Unified Parameters: All settings (e.g., array size, max distance, test count limit) apply uniformly. You can manage them from one place, instead of configuring multiple separate tools.


Extended Insight with Multiple VWAP Lines
Since VWAP reflects the volume-weighted average price for each chosen period, historical lines can show zones where the market had a fair-value consensus in previous intervals. When the script preserves these lines, you see potential support/resistance areas more distinctly. If, for instance, price continually pivots around an old VWAP line, that may reveal a strong volume-based level. With several older VWAP lines on the chart, you gain an immediate sense of where these volume-derived averages have appeared and how price reacted over time. This wider perspective often proves more revealing than a single “current” VWAP line that does not reflect previous anchor sessions.

Handling of Illiquid Markets and Volume Limitations
VWAP is inherently tied to volume data, so its reliability decreases if volume reporting is missing or if the asset trades with very low liquidity. In such cases, a single large trade might momentarily skew the VWAP, resulting in “false” test signals when the high/low range intersects an abnormal price swing. If you suspect the data is incomplete or the market is unusually thin, it’s wise to confirm the validity of these VWAP lines before using them for any decision-making. Additionally, unusual market conditions—like after-hours trading or sudden high-volatility events—may cause VWAP to shift quickly, setting up multiple lines in a short time.

Key User-Configurable Settings
  • Hide VWAP on Day timeframe and above: Lets you disable the primary VWAP plot on daily or higher timeframes for a cleaner view.
  • Anchor Period: Select from Session, Week, Month, Quarter, Year, Decade or Century. Controls how frequently the script resets and preserves the VWAP line.
  • Offset: Moves the current VWAP line by a specified number of bars if you need a shifted perspective.
  • Max Array Size: Caps how many past VWAP lines the script will remember. Prevents clutter if you’re charting very long histories.
  • Max Distance: Defines how far back (in bar index units) a line is kept. If a line’s start bar is older than this threshold, it’s removed, keeping the chart uncluttered.
  • Max Red Labels: Limits the number of tested (red) VWAP lines that appear. If price tests a large number of old lines, only the newest red labels remain once you hit the set limit.


Workflow Overview
  • As soon as a new anchor period begins (e.g., a new weekly candle if “Week” is chosen), the script ends the current VWAP and stores that final value in its internal arrays.
  • It creates a dotted line and label representing the completed VWAP, and keeps track of whether it has been tested or not.
  • Subsequent bars may then cross that line. If a bar’s high/low includes the line’s value, it’s flagged as tested, labeled red, and a test counter increases.
  • As new anchored periods come, old lines remain visible—unless they fall outside your maxDistance or you exceed the maximum stored line count.


Real-World Benefits
Combining multiple VWAP lines—ranging, for example, from session-based lines for intraday perspectives to monthly or quarterly lines for broader context—provides a layered view of the volume-based fair price. This can help you quickly spot zones where price repeatedly intersects old VWAPs, potentially highlighting where bulls or bears took action historically. Because this script automates the management of all these lines and flags their retests, it removes a great deal of repetitive manual work that would typically accompany multiple, separate VWAP indicators set to different anchors.

Limitations & Practical Use
As with any volume-related tool, the script depends on reliable volume data. Assets trading on smaller venues or during illiquid periods may produce spurious signals. The script does not signal buy or sell decisions; rather, it helps visually map out where volume-weighted averages from previous periods might still be relevant to market behavior. Always combine the insight from these historical VWAP lines with your existing analytical approach or other technical and fundamental tools you use.

Conclusion
This script unifies past and present VWAP lines into one overlay, automatically detecting new anchor resets, storing the final VWAP values, and indicating whenever old lines are retested by price. It offers synergy through the simultaneous display of multiple historical VWAP lines, making it quicker and easier to detect potential support/resistance zones and better reflect changing market volumes over time. You no longer need to manually create, configure, or reset multiple VWAP indicators. Instead, the script handles all aspects of line creation, retest detection, and clutter management, giving you a robust framework to observe how historical VWAP data aligns with current price action.

By understanding the significance of multiple anchored VWAP lines, you can assess market structure from multiple angles in a single view. As always, ensure you confirm the reliability of the volume data for your particular asset and use these lines in conjunction with other analyses to form a well-rounded perspective on current market behavior.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน