INVITE-ONLY SCRIPT

ZenAlgo - Detector

237
This script combines multiple volume data sources, calculates several forms of volume-based metrics, displays a table for Spot vs. Perpetual volumes, and visualizes several technical elements (such as cumulative delta, divergences, fractals, and specialized moving averages). The primary objective is to help analyze volume activity across different exchanges, compare Spot vs. Perpetual markets, and observe how shifting volumes may coincide with price action characteristics. This description aims to clarify each component, explain how the calculations are performed, and show you how to interpret the various chart markings.

Why Combine These Metrics in One Script?
Many publicly available volume-related tools focus only on a single exchange or a single type of volume (like spot or futures). This script merges multiple exchange sources for spot and perpetual data into a unified view. By doing so, users can detect discrepancies or confirm alignment between different markets without juggling multiple indicators. It also processes volume-derived signals (delta, divergences, fractals, etc.) in one place, sparing you from manually combining various standalone scripts. Through this integration, it becomes easier to observe how price and volume interact across different market segments.

Core Concept: Aggregated Volume
The script begins by collecting volumes from multiple exchanges in two categories:
  • Spot volumes – Typically aggregated under symbols ending with "USDT" or a user-selected currency, and
  • Perpetual volumes – From perpetual futures contracts (e.g., symbols ending in "USD.P" or "USDT.P").

All these exchange volumes are requested via the built-in request.security() function in a single line for each exchange. The user can enable or disable each exchange in the inputs. The script then calculates an "aggregated volume" for Spot, an aggregated volume for Perpetual, and an overall combined total.

This aggregated volume is used later to break down how much of each bar's volume can be considered "buy" or "sell" based on the bar's candle structure (body vs. wicks).

Volume-Based Calculations: Buy vs. Sell Volume and Delta
For each bar, the script estimates how much of the aggregated volume can be associated with a "buy side" and a "sell side."
  • Volume Buy is computed if the bar's close is above the open, giving more weight to the candle's body and allocating some portion of volume to the wicks as well.
  • Volume Sell is similarly computed if the bar's close is below the open.

This results in a Delta value: Delta = (Buy Volume) – (Sell Volume).

Additionally, the script accumulates these values over a user-defined "lookback length" to provide Cumulative Delta. This can help show longer-term directional volume bias.

Table: Spot vs. Perpetual Comparison
There is a toggle ("Show Spot vs Perpetual Table") that displays an on-chart table comparing volumes:
  • Buy Volume and Sell Volume for each aggregated category (Spot, Perp, and their sum).
  • Delta (the difference between Buy and Sell).
  • Percentage breakdowns of buy vs. sell portions.

This table only appears on the most recent bar and helps users quickly assess how Spot and Perpetual volumes compare, plus the overall total.

PVSRA Color Coding
A "PVSRA-style" color approach classifies each bar based on volume and candle range:
  • Climax Up (lime) or Climax Down (red) occurs if volume is extremely high relative to a simple moving average of volume and range.
  • Above-Average Up (blue) or Down (fuchsia) occurs if volume is moderately higher than average.
  • Otherwise, colors fall back to neutral up/down colors.

This allows you to spot potentially high-volume "climax" bars vs. bars with only moderate or typical volume levels.

Fractals and Divergences
The script detects certain fractal points on the aggregated volumes (sum of buy or sell volumes). It looks for a 5-bar pattern (with the current bar in the middle for top or bottom fractals).
  • When a fractal is confirmed on buy volume, the script checks if new higher price highs coincide with lower buy-volume peaks (or vice versa) to highlight regular or hidden divergences.
  • Similar logic is applied on the sell-volume side if new lower price lows occur alongside higher sell-volume troughs (or the opposite).

If enabled in the settings, lines and labels may appear on the chart to mark these divergence points.

"Delta Dot" Events
This script draws small circles above or below bars when the total delta changes magnitude relative to the previous bar by certain user-defined multipliers. It segregates "tiny," "small," "large," and "extra" expansions in bullish or bearish delta.
  • Bullish Dots: Appear above the bar when the new positive delta is multiple times bigger than the previous positive delta.
  • Bearish Dots: Appear below the bar in a similar fashion for negative delta.

These dots emphasize large or sudden shifts in buy/sell pressure from one bar to the next.

Delta MA and its Direction
A moving average is calculated on the total delta and optionally multiplied by a factor (in the code, by 4) to make it visually prominent. The user can pick from SMA, EMA, WMA, RMA, or HMA as the smoothing technique.
  • Delta MA Direction: The script compares the current delta MA to a short SMA of itself to define whether it is rising or falling.
  • A color is assigned—blue if rising, orange if falling, gray if they're roughly equal.

This helps quickly visualize longer-term momentum in the net delta metric.

Divergences on the Delta MA
After computing the "Delta MA" line, the script detects pivot highs or lows on that line. If the price makes a new high but the Delta MA pivot is lower (and vice versa), it draws lines and small labels indicating potential divergence.
  • Bearish Divergence: Price makes a higher high, while the Delta MA pivot forms a lower high.
  • Bullish Divergence: Price makes a lower low, while the Delta MA pivot forms a higher low.


RSI + MFI Computation
The script also calculates a simplified form of RSI+MFI by comparing (close – open) / (high – low) * a multiplier, then smoothing it with a simple average. This is purely for an optional observational measure to see if the price action is leaning bullish or bearish in terms of these combined indicators.

EMA Overlay and Diamond Shapes
There are two standard EMAs (13 and 21). The script checks whether price is above or below these EMAs, in addition to other conditions (like changes in delta, volume, or RSI+MFI direction) to draw diamond shapes at the top or bottom of the chart:
  • Green Diamonds near the bottom if the conditions line up to suggest that the environment is more favorable for bullish pressure.
  • Red Diamonds near the top if the environment suggests more bearish pressure.


These diamonds come in two sizes:
  • Normal – More pronounced, typically plotted if RSI+MFI result is above/below zero.
  • Small – Plotted if RSI+MFI is on the other side of that threshold.

An optional "Hardcore Mode" adds special tiny diamonds under specific delta color/condition mismatches.

How to Interpret the Chart Elements
  • Line Plots of Buy and Sell Volumes: A positive line for buy volume, a negative line for sell volume, and a zero-line for reference. This provides at-a-glance perspective on how buy or sell volumes add up per bar.
  • Histogram "Total Delta": A color-coded bar that quickly shows whether overall buy vs. sell volume is dominant. The color is governed by the PVSRA logic (e.g., potential climax or above-average conditions).
  • Volume Table (when enabled): Summarizes volumes in numeric and percentage form for Spot, Perp, and total categories on the last bar.
  • Delta Dots: Small circles highlighting abrupt changes in delta magnitude. Larger multiples indicate bigger jumps compared to the previous bar.
  • Fractals & Divergence Lines: Connect pivot points in buy/sell volume or in the Delta MA line with price highs/lows to indicate potential divergences.
  • Delta MA Plot: Smooth curve (scaled up x4) to reflect longer-term accumulation or distribution in the delta. Colored by whether the MA is above or below a short average of itself.
  • Diamonds: Appear when certain volume, price, RSI+MFI, and delta conditions converge. Green diamonds near the bottom typically coincide with bullish conditions, red diamonds near the top with bearish conditions.


Practical Usage Notes
  • Use the Spot vs. Perp breakdown to see if these two market segments differ significantly in their contributions to total volume. This can be informative when a certain type of market (futures vs. spot) might be "driving" price action.
  • The PVSRA color scheme highlights "climax" or "above-average" volume bars, which can sometimes appear around major reversals or breakouts.
  • Observing divergences in aggregated buy/sell volume (or in the Delta MA line) can provide additional context on whether certain price moves are backed by strong volume involvement.
  • The script's fractal divergences rely on short pivot detection. Signals will appear only after enough bars have passed for confirmation, so these are effectively "after-the-fact" notations to illustrate possible volume/price divergences.
  • The diamonds do not necessarily instruct any buy/sell action; rather, they mark conditions where multiple volume and momentum criteria line up in one direction.


Important Considerations
  • This script displays aggregated volumes from potentially multiple exchanges. Each exchange or pair might have different time zones, liquidity, or data availability, which can occasionally result in incomplete or zero values.
  • All references to "buy" or "sell" volume are approximate breakdowns based on candle structure. They are not absolute measures of real-time order flow.
  • Divergences and fractal points are provided strictly for analytical insight. They can repaint or shift if the fractal conditions were not fully confirmed in real time.
  • The color-coded lines, histograms, diamonds, and tables are strictly to guide analysis of volume fluctuations and do not claim to predict future price performance.
  • If you enable "Hardcore Mode," you will see additional diamond markers. This mode is mainly intended as an extra highlight of certain "contradictory" delta conditions.


Summary
The "ZenAlgo - Detector" script brings together a variety of volume-based analyses:
  • Aggregated volumes from multiple exchanges
  • A breakdown into Spot vs. Perpetual activity
  • Delta calculations, fractal divergences, and a specialized Delta Moving Average
  • Color-coded bars reflecting possible PVSRA concepts
  • A table to highlight numeric differences and percentages
  • Additional overlays (e.g., diamonds, RSI+MFI synergy, etc.)


In contrast to many free, single-exchange indicators, this script centralizes multiple exchange volumes in one place, making it easier to observe and compare volume flows across different market types (spot vs. perpetual). Users no longer need to rely on scattered tools or separate overlays to check volume divergences, fractals, or specialized MA calculations—everything is unified here. By carefully monitoring the table, Delta histogram, color-coded bars, divergence lines, and diamond markers, traders can more comprehensively evaluate how volume and price interact. Each plot is designed to showcase different aspects of volume flow—such as whether spot or derivatives markets dominate, if volume is skewed toward buying or selling, and if there are divergences between volume momentum and price movement.

All computations are displayed to help you carry out a more informed market analysis. It is strongly advised to combine these observations with other risk management or analytical methods, rather than relying on any single indicator alone.



כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.