INVITE-ONLY SCRIPT

ZenAlgo - Squeeze

72
This indicator is a separate-pane tool that reads the current chart symbol (treated as the traded instrument, typically a perpetual) and optionally reads a second symbol used as a comparison reference. It can operate in two broad modes:
  • Basis on - the script attempts to obtain a "spot or reference" close and compares the chart close against it.
  • Basis off - all basis related parts are disabled and only the on-chart derived components remain.

The comparison reference can be selected via presets (dominance and market cap style tickers, BTC perpetual, etc.) or via a manual symbol selector. There is also an optional second comparison line that is visual-only and does not influence the squeeze logic.

Spot and reference selection, including safety and fallback

When basis mode is enabled, the script needs a valid comparison close series. It supports three ways to obtain it:
  • Manual selection - you choose a specific reference symbol or one of the provided presets.
  • Auto spot from the chart symbol - the script strips the ".P" suffix from the chart ticker to guess a spot ticker (fast, but can be invalid on some symbols or spread charts).
  • Exchange fallback chain - if the manual request fails to return data, the script tries a hardcoded sequence of exchanges for the same base pair (same exchange prefix first, then Binance, then Bybit, then MEXC, then Bitget). It uses requests that ignore invalid symbols so the script fails gracefully into the next option. Spread-style synthetic tickers are detected and excluded from this fallback process.

Why this matters: basis style comparisons are only meaningful when the reference series is actually available and aligned to the same timeframe. The script spends a lot of logic on preventing runtime failures and preventing accidental "fake basis" on unsupported tickers.

VWAP with standard deviation bands on multiple reset schedules

The next major block computes anchored VWAP states for several higher-level periods. The core approach is:
  • It performs a running, volume-weighted accumulation of typical price for the anchor period.
  • It simultaneously accumulates the second moment needed to estimate dispersion around VWAP, producing a standard deviation estimate around the anchored VWAP.
  • On each reset boundary (daily, weekly, monthly, quarterly, semiannual, yearly), the accumulators reset and begin a new anchored VWAP segment.

Why this matters: anchored VWAP is treated here as a rolling "fair value" for the current period. The dispersion estimate is used to convert distance from VWAP into discrete states (premium, discount, etc.) instead of relying on raw price distance, which varies widely across assets.

Smoothed average line used as a slower trend filter

Alongside the anchored VWAPs, the script builds a slow baseline from the chart close using a two-stage smoothing process. This baseline is then used as a slower reference for trend qualification.

Why this matters: the trend logic requires alignment between price, the daily anchored VWAP, and this slower baseline, plus confirmation that both the daily VWAP and the slow baseline are rising or falling. This avoids classifying trend from price position alone.

Trend classification used for context labeling

Trend is classified as:
  • Bull trend when price is above the daily anchored VWAP, the daily anchored VWAP is above the slow baseline, and both the daily VWAP and the slow baseline are rising.
  • Bear trend when price is below the daily anchored VWAP, the daily anchored VWAP is below the slow baseline, and both are falling.

If neither is true, the script treats trend as neutral for its table and for squeeze sub-labeling.

Why this matters: the script later distinguishes events that align with the prevailing trend versus those that run against it.

VWAP state mapping and heatmap rows

For each anchored VWAP (D, W, M, Q, S, Y), the script assigns a discrete state label based on where price is relative to VWAP and how many dispersion units away it is. The state labels include:
  • Above, Below
  • Premium and Discount tiers
  • "Super" and "Mega" tiers for more extreme distances

These states are turned into colors using a selected palette preset. The script then draws horizontal "heat" lines at fixed Y offsets inside the indicator pane, one row per anchor timeframe, plus optional row-letter labels that also show whether the anchored VWAP is rising, falling, or stable.

How to interpret:
  • The heatmap is not a price plot. It is a categorical summary of where current price sits relative to each anchored VWAP and its dispersion.
  • Multiple rows allow you to see whether price is simultaneously extended on short anchors but neutral on long anchors, or vice versa.

Normalized metrics used for squeeze detection and plots

The script computes several standardized (z-scored) series over a fixed lookback length:
  • Chart close z-score - how far the current close is from its recent mean in standardized units.
  • Reference close z-score - same standardization on the chosen comparison series (only when basis is enabled and reference exists).
  • Basis percentage z-score - derived from the ratio between chart close and the reference close, transformed into percent difference, then standardized.
  • Delta proxy z-score - a signed volume proxy that assigns positive weight on up candles, negative weight on down candles, and zero on unchanged candles, then standardized. For symbols with missing volume, it can fall back to a constant weight of 1 depending on settings.

Why this matters:
  • The use of z-scores makes thresholds portable across assets and regimes. Instead of using raw basis percent or raw volume, the script detects whether each component is unusually large relative to its own recent distribution.

Squeeze event conditions and "continuation vs countertrend" labeling

The core squeeze events are defined by three simultaneous conditions, each compared to a fixed threshold:
  • Price is moving fast enough (rate-of-change threshold).
  • Basis deviation is large enough in one direction (basis z-score threshold).
  • Delta proxy deviation is large enough in the same direction (delta z-score threshold).

When these align to the upside, the script calls it a short squeeze event (upward acceleration with positive basis and positive delta proxy abnormality). When they align to the downside, it calls it a long squeeze event (downward acceleration with negative basis and negative delta proxy abnormality).

Volume availability handling:
  • You can hard-disable squeeze detection on symbols where volume is missing.
  • Or you can allow it, in which case the delta proxy uses a fallback weight so the pipeline still functions.

Continuation vs countertrend:
  • Each squeeze event is classified relative to the trend state described earlier.
  • A squeeze that agrees with the trend is marked as continuation.
  • A squeeze that opposes the trend is marked as countertrend.

Visual output tied to squeezes:
  • Optional dots are plotted near the top or bottom of the pane to indicate event type (short vs long, continuation vs countertrend).
  • Optional candle coloring is applied only during squeeze states, using separate colors for continuation bull, continuation bear, and countertrend.

Basis vs chosen comparison relationship on fixed timeframes

In addition to the main squeeze logic, the script evaluates how the basis z-score compares to the chosen reference z-score on four fixed intraday timeframes (5m, 15m, 1h, 4h). For each timeframe it assigns a simple state:
  • Basis standardized value above the reference standardized value
  • Basis standardized value below the reference standardized value
  • Equal or unavailable

These states are primarily used to color table cells as a compact multi-timeframe context readout.

Why this matters: it provides a quick view of whether the basis deviation is leading or lagging the chosen reference across multiple granularities, without changing the main squeeze definitions.

Cross between basis and chosen reference

When enabled and basis is available, the script detects crosses between:
  • Basis z-score line
  • Chosen reference z-score line

It can plot small up or down triangles on the basis plot when the basis standardized value crosses above or below the reference standardized value. The triangle color is tied to the daily VWAP heat color so the marker inherits the daily premium/discount context.

Why this matters: it isolates regime changes where the basis deviation becomes stronger or weaker than the reference series in standardized terms, which can be used as a context shift rather than a standalone entry indication.

Pane plots, fills, and thresholds

The indicator pane can show:
  • The chart close z-score line (perp series).
  • The chosen reference z-score line (compare series, when available).
  • The basis z-score line.
  • The optional second comparison z-score line.

A background fill is drawn between the chart close z-score and the reference z-score to visualize which is higher at the moment. Horizontal reference lines are also drawn for:
  • The basis z-score thresholds used for squeeze logic.
  • The delta proxy z-score thresholds used for squeeze logic.
  • Zero line and additional guide lines at several standardized levels.

How to interpret values:
  • The plotted values are standardized units relative to each series’ own recent distribution.
  • A value around 0 indicates "near recent average."
  • Large positive or negative values indicate "unusually above or below recent average" for that specific series.

Table readout and derived bias score

A table can be shown in the top-right of the pane, summarizing:
  • Current mode (basis off, auto spot, or which preset/manual reference is in use).
  • Whether basis data is valid.
  • Trend state and a slope warning/ok flag.
  • Daily and weekly anchored VWAP numeric values and their premium/discount state coloring.
  • A daily vs weekly VWAP difference state.
  • Price rate-of-change state.
  • Basis percent value and basis z-score state.
  • Delta proxy z-score state.
  • Chart close z-score state.
  • Reference z-score state.
  • A composite bias score and text label.
  • The four timeframe basis-vs-reference relationship states (5m, 15m, 1h, 4h).

The score is then mapped to labels from strong bearish through neutral to strong bullish, optionally appending the most recent squeeze classification when present.

Right-side value tags

On the last bar, the script can draw short horizontal lines and labels to the right showing the latest values for:
  • Chart close z-score
  • Reference z-score
  • Basis z-score
  • Optional second comparison z-score

These tags are offset a user-selected number of bars into the future so they remain readable.

"Best" block and alert conditions

A final logic layer uses:
  • Two fixed thresholds on the basis z-score (one associated with an "up" cross and one with a "down" cross).
  • A count of how many enabled VWAP heatmap rows are currently in "hot" states (above or premium tiers) vs "cold" states (below or discount tiers).
  • A recent-squeeze filter that checks whether any squeeze event happened within a defined lookback window.

It then plots:
  • Small circles for threshold crosses when at least a minimum hot/cold alignment exists.
  • Diamonds when alignment exists, optionally larger when alignment count is higher.
  • Separate diamonds when the threshold cross happens without a recent squeeze.

Alert conditions are provided for:
  • Strong "best" diamonds when alignment meets a higher minimum.
  • Optional alerts for "best" threshold crosses without recent squeezes.
  • Optional alerts for basis-vs-reference z-score crosses.

Why this matters: it gates threshold events by broader multi-anchor context, attempting to avoid treating a single standardized cross as equally meaningful in every macro positioning regime.

Added value over common free indicators

This script combines several components that are often separate in typical tools, and it enforces explicit data-availability safeguards:
  • Anchored VWAP states across multiple calendar resets with an internal dispersion estimate and a compact heatmap summary.
  • Basis style comparison that can be driven by multiple preset market references, with a fallback chain across exchanges and explicit spread-chart protection.
  • Squeeze detection that requires simultaneous agreement across price acceleration, basis deviation, and a signed volume proxy deviation, then labels the event by trend alignment.
  • A unified pane where standardized series, thresholds, heatmap context, and table diagnostics are all consistent with the same internal state.

Disclaimers and where it can fall short
  • If the chosen reference symbol is unavailable or returns gaps, basis-dependent outputs can be unavailable or may switch to fallback sources depending on settings. This can change the basis series behavior compared to a strictly fixed reference feed.
  • The delta component is a proxy based on candle direction and volume, not an exchange order-flow delta. On symbols with unreliable volume, enabling fallback weighting can keep the indicator running but reduces the meaning of "volume-driven" parts.
  • Standardized values depend on the chosen lookback. In highly non-stationary regimes, what is "unusual" can shift quickly.
  • Anchored VWAP states depend on reset definitions in UTC. If your trading session expectations are tied to different session boundaries, interpret anchor transitions accordingly.

How to best use it
  • Start by verifying Basis OK in the table when basis mode is enabled. If it shows an error state, either switch reference mode, disable basis, or enable fallback if appropriate for your symbol.
  • Use the heatmap rows to understand whether price is extended relative to multiple anchored baselines simultaneously or only on short anchors.
  • Treat squeeze dots and candle coloring as event markers, then use the trend label (continuation vs countertrend) and the VWAP states to decide whether the event aligns with your broader plan.
  • Use basis vs chosen crosses and the basis-vs-reference multi-timeframe states as context shifts, not as isolated triggers.
  • If you enable alerts, prefer those that include the multi-row hot/cold alignment gating when you want fewer, more context-filtered notifications.

免責事項

この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。