INVITE-ONLY SCRIPT

ZenAlgo - Control

66
ZenAlgo - Control plots volume profile reference levels for several higher time windows and keeps those levels visible on the chart with labels and optional alerts. It is designed to work on intraday charts and uses the symbol's traded volume to estimate where the most activity occurred within each period.

Inputs and session alignment
Session start offset (hours) shifts the time used to decide when a new week, month, quarter, semi annual period, or year begins. This is useful when you want the period boundary to align with a specific exchange session, or when you want weekly boundaries to start at a different hour than the default.

Profile levels controls how finely the script bins price into equally sized price slices between the current period's high and low. More levels means a finer histogram (more detail, more computation).

Max rebuild bars limits how far back the script will look when it must rebuild the entire histogram (explained below).

Value Area % sets how much of the total estimated volume the value area should contain (default 0.68).

Label offsets control how far to the right the labels and lines extend, so the levels are readable without covering current candles.

Period availability and timeframe gating
The indicator conditionally runs each period engine depending on the chart timeframe to avoid heavy calculations where it is not intended.
  • Weekly is available on intraday timeframes below 1D (for example 1m to 4h).
  • Monthly is available on intraday timeframes at or above 15m.
  • Quarterly, Semi Annual, and Yearly are available on intraday timeframes at or above 1h.
  • The script disables these engines on D, W, M chart timeframes as described in the input tooltips and gating logic.

This matters because the calculation builds a histogram from bar ranges and volumes, which becomes expensive on very low timeframes over very long history.

Core idea - building a volume by price histogram from candles
For each enabled period (weekly, monthly, quarterly, semi annual, yearly), the script maintains:
  • The running high and low of the current period
  • A fixed number of price bins spanning that high to low range
  • An array holding estimated volume per price bin

For every new bar inside the current period, the script distributes that bar's volume into the bins that overlap the candle's low to high range. The distribution is weighted by how much of the candle's range overlaps each bin, so a candle that spans many bins contributes proportionally rather than assigning all volume to a single price.

Why this works conceptually:
  • Volume profile levels aim to identify prices where the market accepted a lot of trading (high participation).
  • Distributing volume across the candle's traded range is a practical approximation on platforms where true tick by tick volume at price is not available to Pine in a universal way.
  • Aggregating many bars over a full period produces a stable histogram where high volume areas stand out compared to low volume areas.

POC and Value Area calculation
Point of Control (POC)
Within a period, the script finds the price bin with the highest accumulated volume and uses the center of that bin as the period's POC level. This is the single price level where the histogram peaks.

Value Area High and Low (VAH, VAL)
After the POC is known, the script expands outward from the POC bin, adding neighboring bins until the cumulative included volume reaches the configured Value Area percentage of the total. It expands by comparing the volume just above and just below, including the larger side first so the chosen area reflects where volume clustered. The resulting upper and lower included bin centers become VAH and VAL.

Interpretation:
  • POC is a single most traded price area proxy for the period.
  • VAH and VAL bound the price region that contains the chosen fraction of the period's estimated volume.
  • When price is inside VA, it is within the range where most period volume occurred. When price is outside VA, it is in the lower participation tails relative to that period's distribution.

Incremental update vs rebuild logic
The histogram depends on the current period's high and low because those define the bin boundaries. When a new bar makes a new high or new low for the period, the bin boundaries would change. If you kept the old histogram, the bins would no longer correspond to the correct price slices.

To handle this, the script uses two modes:
  • Incremental update when the period high and low do not change on the new bar. It simply adds the new bar's weighted volume into the existing bins and recalculates the POC from the updated histogram.
  • Rebuild when the period makes a new high or new low. It clears the histogram and reconstructs it by iterating back over bars in the current period (up to Max rebuild bars), re distributing each bar's volume into the newly defined bins.

This approach keeps levels consistent with the current period range, at the cost of occasional heavier computation when the range expands.

Current period dPOC and previous period levels
The indicator draws two categories of levels per period.

Current period dPOC (running)
For each enabled period, the script plots a dotted line at the current period's running POC and labels it as dPOC (dynamic POC). It is dynamic because it changes while the period is still forming as new volume comes in and as the period range expands.

Previous period fixed levels
When a period rolls over (for example, a new week starts), the script stores the finished period's final POC, VAH, and VAL as previous levels. It then draws those previous levels across the current chart with solid (POC) and user selected styles (VAH, VAL), plus labels. These previous levels remain fixed until the next rollover of that period.

Why both exist:
  • The running dPOC reflects where trading is concentrating in the current unfinished period.
  • The previous period POC and VA levels provide stable references derived from a completed distribution, which does not change retroactively.

Visual plotting details
  • Each period has separate color settings for POC and dPOC, plus optional VAH and VAL with configurable line width and line style (solid, dashed, dotted).
  • Labels print the formatted level value using the symbol's minimum tick formatting, and for very large numbers the label shortens the text with K, M, B, T suffixes to keep labels readable.
  • Lines and labels are positioned to the right of price using the configured bar offsets. The script includes a safety limit on how far back the left anchor can be placed to avoid platform constraints when loading long history.

Alerts - touch and cross logic
Alerts are optional and can be configured per period and per level category.
You can enable:
  • TOUCH: triggers when the candle's low is at or below the level and the high is at or above the level (the bar range includes the level).
  • CROSS: triggers when the close crosses the level.
  • HIT is defined as TOUCH or CROSS.

You can choose to alert on:
  • Current running dPOC levels
  • Previous period POC and, if enabled, previous period VAH and VAL
  • Weekly, Monthly, Quarterly, Semi Annual, Yearly independently

How to interpret the plotted values
  • dPOC (W, M, Q, S, Y): the current period's running POC estimate. It can move during the period and can shift more noticeably when the period range expands and a rebuild occurs.
  • POC (W, M, Q, S, Y): the previous completed period's POC. This is fixed for the duration of the next period.
  • VAH / VAL (W, M, Q, S, Y): the previous completed period's value area boundaries for the configured value area percentage.

A practical reading:
  • Previous POC and VA can be used as higher timeframe reference levels on lower timeframe charts because they summarize where volume concentrated over larger windows.
  • The current dPOC helps track where volume is concentrating inside the currently forming period.

Best use and workflow
Common ways to use these levels as references:
  • Use previous period POC and VA as context zones, then make lower timeframe decisions with your existing execution tools.
  • Treat dPOC as a live read of where the current period is building acceptance, and compare it to the fixed prior levels.
  • Use alerts to reduce screen time by being notified when price interacts with selected levels (touch or close cross).

Settings guidance:
  • Higher Profile levels increases detail but can be heavier on performance, especially when rebuilds occur.
  • If you need lighter computation on very active charts, reduce Profile levels or reduce Max rebuild bars.
  • If you want period boundaries to align with a specific session, adjust Session start offset.

Added value compared to free alternatives
This script focuses on a specific combination that is not always available together in simpler public indicators:
  • Simultaneous tracking of multiple higher time windows (weekly, monthly, quarterly, semi annual, yearly) with independent enable toggles and styling.
  • Side by side display of current running dPOC and previous completed period levels for each enabled window.
  • A candle range weighted volume distribution into bins, rather than assigning the entire bar volume to a single price proxy.
  • Built in alert conditions for touch and close cross across all supported windows and level types, so level interaction can be monitored without manual checking.
  • Label formatting that respects the symbol's tick size and shortens very large values for readability on indices and aggregates.
  • All supported periods are calculated using the same volume distribution model, the same binning logic, and the same rebuild rules. This ensures that weekly, monthly, quarterly, semi annual, and yearly levels are directly comparable to each other, unlike combining multiple separate indicators that may use different assumptions, aggregation methods, or update behavior. Using a single engine also enables consistent alert definitions and synchronized updates across all periods.

Disclaimers and where it can fall short
  • The volume at price distribution is an approximation derived from candle ranges and bar volume. It is not a true tick level volume profile, and results can differ from exchange native volume at price data.
  • On symbols where the reported volume is limited, synthetic, or not representative (some indices, some CFDs, some venues), the histogram is based on the volume series TradingView provides for that symbol, which may affect the usefulness of volume derived levels.
  • The current dPOC can change within the period and can jump when the period makes a new high or low, because a rebuild recalculates the histogram using the updated range.
  • Performance depends on timeframe, history loaded, Profile levels, and how often the period range expands. If you see slowness, reduce Profile levels or Max rebuild bars, or disable some periods.
  • This indicator plots reference levels only. It does not determine entries, exits, position sizing, or risk limits.

כתב ויתור

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