Opening Price Deviation Tracker v2 - Buffer Zones - VWAP [ViZ]OPENING PRICE DEVIATION TRACKER v2 — BUFFER ZONES — VWAP
WHAT IT DOES
Measures how far price has travelled from the opening price of a chosen anchor
period, and maps that distance onto a fixed percentage grid on the chart.
The reasoning is that the open of the current period is a reference every
participant on the instrument shares, and that distance from it expressed in
percent is comparable across instruments and across time in a way raw price
distance is not. A 1% move from the weekly open means the same thing on a
30,000-point index as on a 40-dollar stock.
Around that single idea the script adds a tolerance band on each level, a
permanent record of which levels each period actually reached, a three-timeframe
summary panel, optional trend and volume references, and three alert channels
that differ in what they detect rather than only in speed.
Every component keys back to the same anchor open. This is not a set of unrelated
tools sharing a pane.
1. THE ANCHOR OPEN, AND WHY IT IS LATCHED
The Timeframe input sets the anchor period — weekly by default, but any timeframe
longer than the chart's.
The script obtains that period's opening price by latching it: on the first chart
bar of a new anchor period, that bar's own open IS the period's open, so the value
is stored and held until the next rollover.
There is no request.security() call anywhere in the script. Not for the anchor
open, not for the three table columns, not for VWAP.
That matters for a specific reason worth stating plainly. The obvious way to build
this is request.security with lookahead enabled, and for an OPEN that is actually
defensible — an open is fixed by the first tick of its period, so requesting it
with lookahead never returns a number that was unknowable at the time. Without the
flag the same call returns the PREVIOUS period's open until the current one closes,
which puts the whole grid one full anchor period behind itself, so simply turning
the flag off is not an option. Latching sidesteps the argument entirely: the value
is a chart bar's own open, so it provably cannot look ahead, there is no
higher-timeframe request to disclose, and there is no real-time-to-historical
transition to reason about. Levels drawn on historical bars are the levels that
genuinely existed at the time, and they do not change on reload.
The period high and low used by the panel are accumulated from chart bars for a
different and stronger reason: a period's extremes are only settled when the period
ENDS, so requesting those with lookahead genuinely would leak future data onto
historical bars. Open safe, extremes not — that distinction is the whole substance
of the question.
Latching does cost something, in the form of four documented behaviours. They are
in the LIMITATIONS section, and reading it will explain most of what could
otherwise look like a bug.
2. THE DEVIATION GRID
From the latched open the script builds five levels above and five below, spaced by
a fixed percentage step, with the 0% line marking the open itself. Line width
increases with distance, so ±1 is a hairline and ±5 is the heaviest — depth is
readable without checking the labels. Each level carries a right-edge label showing
both its price and its percentage offset. Colours darken progressively outward from
the two base colours you set.
The step comes from a preset list, each labelled with its own value:
0.25% — scalping / very low volatility
0.3875% — reactive / lower timeframes
0.50% — intraday
1.00% — balanced (default)
2.00% — swing / higher timeframes
3.00% — high volatility / highest timeframes
Custom — any value from 0.1 upward
Because the grid always runs to five levels, the step also fixes its total span: 1%
covers ±5%, 2% covers ±10%, 0.25% covers ±1.25%. Pick the step whose span roughly
brackets what your anchor period typically moves. Too small and price sits
permanently off the top or bottom of the grid; too large and it never leaves the
first band, and nothing the script draws will tell you anything.
As orientation rather than instruction: the lower steps suit major FX pairs and
large-cap equities on intraday anchors, the middle of the range suits indices and
most equities on daily and weekly anchors, and the upper steps suit small caps,
commodities and crypto, or any weekly-and-above anchor. Volatility varies more
inside an asset class than between them, so verify against the instrument in front
of you and switch to Custom once you know what you want.
The step also drives the panel's Zone and To Next rows, the buffer positions, touch
detection and the markers — one number, one grid, everywhere.
3. LINE DISPLAY
Three modes:
Off — no grid lines; panel, markers and alerts still work
Show All — full grid across history and the live period
Touched Only (Historical) — live period shows the full grid; completed periods
keep only the levels price actually reached
The third is the default and is the one worth understanding. On a chart with months
of history, showing all eleven lines per period is unreadable. Retaining only the
levels each period actually reached leaves a permanent record of how far each period
extended — which is usually the only thing you wanted from the older periods.
Those historical segments are stored as drawn objects and accumulate without an
explicit cap, bounded only by TradingView's 500-line budget. When the ceiling is
reached the platform deletes the oldest, so the recent history you actually look at
is never what disappears. The 0% opening line is exempt from filtering and always
renders in full.
4. BUFFER ZONES
Each deviation level, and the open itself, can carry a translucent band drawn a set
percentage of price above and below it — eleven bands in total.
Two reasons for them. Price rarely reacts at an exact tick; it reacts in a region
around a reference, so a band represents the level more honestly than a line. And
the band gives an anticipatory alert trigger: entry into the band fires before the
level is reached.
The live period's bands are drawn spanning the current period. Bands from previous
periods are also retained, but only for levels that were actually touched, so past
structure appears where something happened rather than as uniform wallpaper.
Historical retention is capped at 44 periods, which is the limit of the platform's
500-drawing budget once the live period's own eleven boxes are accounted for; lower
it freely for a cleaner chart, nothing else depends on it.
One interaction to be aware of: buffer size is a percentage of price and does not
scale with the grid step. Lead time depends on the RATIO of the two, not the
absolute size. At roughly a quarter of the deviation step the warning is genuinely
early; at half or more the warning and the touch collapse into the same bar. The
default 0.15 against a 1% grid is 15%. Against the 0.3875% preset the same value is
39%, which effectively eliminates the early warning; against the 3% preset it is 5%,
which may be too tight to see. If you change the step, check the buffer against it.
5. TOUCH MARKERS
Optional, and off by default. A small marker is placed on the first bar of each
period that reaches each level — one marker per level per period, re-armed at every
rollover.
Marker shapes:
● circle — touch: the bar's range reached the level.
▲ ▼ triangle — acceptance: the bar CLOSED beyond the level. Points up above the
open, down below it.
◆ diamond — rejection: the bar tagged the level and closed back, with a retreat wick
larger than the threshold you set.
✕ cross — gap through: the bar reached the level without trading into it.
Three detail modes let you take just the touches, touches plus acceptance, or the
full touch / rejection / acceptance set. Rejection sensitivity is adjustable as a
fraction of the bar's range, 0.5 by default; raise it toward 0.65 for a stricter
read. Marker range is adjustable up to ±5 levels, ±4 by default. The 0% line can be
marked too, optionally. Colours inherit from the grid by default, so a +3 marker
matches the +3 line; the 0% marker is always blue to match the opening-price line.
Each marker's tooltip states the level and the classification.
Markers use the same reach test as the historical line segments — directional above
and below the open, straddle at 0% — so a marker and a retained line segment can
never disagree about whether a level was touched. Markers appear at bar close by
default; an option tags them on the live bar instead, in which case the shape may
still change before the bar closes, because acceptance and rejection both depend on
where the bar ends up. That option is visual only and affects no alert.
6. BAR COLOURING
Optional, with two selectable sources.
Deviation Levels colours each bar by which of the eleven grid zones it closed in,
using the same progressively darkening shades as the lines, with the "between
levels" colour for bars inside the first band. The candles then carry the deviation
reading themselves, which means you can switch the grid off entirely and still see
depth — a genuinely clean chart that still reports.
VWAP / Bands colours by position relative to the anchored VWAP and its bands
instead: five zones, beyond the outer band, beyond the inner band, and between, on
each side. It falls back to plain above/below VWAP when bands are off. Useful when
you want the grid for structure but volume-weighted price for bias. This mode needs
only volume and a valid anchor, so it works with the VWAP line itself hidden.
Bars before the first anchor rollover are deliberately left uncoloured rather than
being painted a default shade, since no zone reading exists for them yet.
7. MOVING AVERAGE
Optional SMA or EMA, adjustable period, 200 by default. Context rather than signal:
it exists so you can see whether a level is being approached with or against the
prevailing trend, which usually matters more than the touch itself.
8. VWAP
Optional anchored VWAP with its own reset selection, independent of the deviation
anchor: daily session, weekly, monthly, quarterly, semi-annual, annual, Match
Deviation Anchor, or a custom timeframe. Daily session matches the standard
TradingView VWAP. The multi-month options are derived from the monthly rollover and
then gated by calendar month, so they land on real calendar boundaries — January /
April / July / October, January / July, and January — rather than drifting from an
arbitrary reference point.
Match Deviation Anchor is the setting for a single consistent frame of reference:
grid and VWAP then reset on the same bar and describe the same period. The
independent options cover the common case of a session VWAP underneath a weekly or
monthly grid.
Two optional band pairs, in either standard-deviation or percentage units, are
independent of the deviation grid preset. The outer pair is rendered a step more
transparent than the inner, so depth reads without a second colour input, and a very
light fill between the inner pair is available but off by default so it does not
compete with the buffer zones. Note that in sigma mode the bands pinch shut at each
anchor reset and flare open over following bars — that is inherent to anchored
standard deviation, not a fault; percentage mode does not do it.
The line and bands are blanked on the anchor bar itself, so the plot BREAKS at each
reset instead of drawing a diagonal from the old period's last value to the new
one's first.
VWAP needs volume, and needs an anchor longer than the chart timeframe. If either
is missing, an on-chart label states which — including when VWAP is hidden but the
VWAP bar-colouring mode is active and starved.
9. THE DATA PANEL
Projects the same deviation grid onto three user-selectable timeframes, each
measured from that timeframe's own latched opening price. Defaults are daily,
weekly and monthly, and the column matching the indicator's own anchor is marked
with a diamond. The title bar shows the active step, for example "1% grid".
Rows, in Full detail:
Open — that period's opening price, at the symbol's own precision.
Δ from Open — percentage move from that open, with a direction arrow. Colour
intensity scales with magnitude, and the saturation ceiling scales as the square
root of the column's length, so at the 1% preset the daily column saturates around
2%, the weekly around 4.5% and the monthly around 9.2%. Each column is therefore
meaningful on its own scale, rather than one fixed ceiling that the longest column
always maxes out.
Zone — which band price currently occupies, shown as "+1 → +2", "0 → -1" and so on,
filled with the SAME colour as the corresponding chart grid line. Beyond the grid it
reads "> +5" or "< -5" rather than silently clamping.
To Next % — distance to the level above and the level below. This is the practical
number for judging whether a target is in reach.
Range Pos — where price sits inside that period's realised high-low range so far, as
a percentage with a small meter. 90% means price is near the top of everything the
period has covered.
State — bullish, bearish or neutral, combining direction from Δ with conviction from
Range Pos, so it is not merely a restatement of the sign of Δ. When the range is
unknown it degrades to direction only.
Compact detail drops To Next and Range Pos and closes the gap rather than leaving
empty rows. The panel's whole surface palette — header band, row banding,
separators, anchor-column wash — is derived from one background colour input, and
text automatically switches to a dark set on light backgrounds. Colour is carried by
text tint throughout, with the Zone row as the single filled block and the panel's
focal point.
Three column states exist. A column SHORTER than the chart timeframe reads "below
chart TF", because a shorter-timeframe open cannot be resolved honestly from a
longer chart bar. A column whose boundary has not appeared inside the loaded chart
history reads "no boundary yet" — see LIMITATIONS. Otherwise it reports normally.
The point of three columns at once is alignment. Bullish daily, bearish weekly,
bullish monthly is a different situation from all three agreeing, and the panel makes
that visible without changing timeframe.
10. ALERTS — THREE CHANNELS
The three channels differ in WHAT THEY DETECT, not only in how fast they report.
Each has its own toggle.
BUFFER (early warning) — fires when price first enters the band around a level.
Dispatches intrabar, the moment the band is entered; delivered at the bar close it
would already have been overtaken by events. On by default.
AT LEVEL — fires on any bar whose range CONTAINS a level, and keeps repeating for
as long as price stays there. Dispatches intrabar, on the first qualifying tick.
This is safe intrabar because the test reads only high and low: inside a live bar
the range only ever widens, so once it engulfs a level no later tick can un-happen
it. The cost is partial reporting — a candle running through +1, +2 and +3 names +1,
because that is what was true at the tick it fired. On by default.
FIRST TOUCH — fires the first time each level is reached in the anchor period, then
stays silent about that level until the next period. Dispatches at bar close,
because its wording carries a classification — touch, closed beyond, rejected — and
all of those read where the bar closed, which on a live bar is only the current
price and could flip tick to tick. Evaluated once on a finished bar, it loops every
level and reports all of them. Off by default. Works with the markers hidden.
The two level channels also DETECT differently, which is why both exist. At Level
requires the bar to straddle the level. First Touch tests directionally, so a bar
that jumps clean over a level without trading back into it is reported by First
Touch and is structurally invisible to At Level. That is the gap-through case, and
it is exactly what a news candle does.
So: buffer and at-level answer "tell me now". First touch answers "tell me
everything, a moment later".
All three messages render as ": | Price: ", with the
buffer channel adding " | Level: ", so anything parsing them downstream sees
one consistent shape. No timestamps are embedded, because every delivery method
TradingView offers already stamps the notification.
TO SET UP: create ONE alert on the indicator with the condition set to "Any alert()
function call". The three toggles decide what it reports. The long string
TradingView pre-fills is the alert's NAME, auto-built from every input — rename it
in the dialog; it is not the message.
If you want a different sound or webhook per channel, add the indicator to the chart
more than once, enable exactly one channel per instance, strip the extra instances
of all drawing, and name each chart alert after its channel. Keep the anchor and
preset identical across instances or the channels start describing different grids.
One known behaviour: if a single bar enters more than one buffer band, the buffer
message names the last one evaluated rather than listing all of them. The alert
still fires; the label is simply not exhaustive. Most visible on fast bars, or when
buffer size approaches half the deviation step and bands begin to overlap.
11. CHOOSING A CHART TIMEFRAME AND ANCHOR
The useful rule of thumb is that the anchor period should span roughly 20 to 100
bars of the chart timeframe. Fewer and the grid has no room to develop; many more
and the levels are too distant to be actionable within a session.
In practice: 1m to 15m charts pair with daily and weekly anchors, hourly and 4-hour
with weekly and monthly, daily and above with monthly, quarterly and annual. For
the panel, suggested column sets are 4H/D/W under a weekly anchor, D/W/M under a
weekly or monthly anchor, and M/3M/12M under a quarterly anchor.
Some ways it gets used:
Mean-reversion context — a level reached early in a period, price stalling inside
the band, moving average leaning the other way, is a different proposition from the
same level reached mid-expansion. The rejection marker is what separates the two
after the fact.
Continuation context — sequential first-touches inside one period, left on the
chart by the touched-only display, show whether a period is expanding steadily or
stalling at the same band repeatedly. Acceptance triangles at successive levels read
differently from a diamond at the same level three times.
Risk framing — because levels are percentage distances, To Next % converts directly
into stop and target distances in the same units you size positions in.
Period bias — the panel alone, grid switched off, works as a compact
three-timeframe bias readout.
Monitoring — the first-touch channel lets you watch a list of instruments for
meaningful extension from their period open without staring at charts, and the
buffer channel gives the heads-up before it happens.
None of the above is prescriptive. The defaults are a reasonable place to start
rather than a recommendation, and the script is deliberately built so that almost
every part of it can be moved without breaking anything else — so move things.
Put the same anchor on three different chart timeframes and watch how the grid
changes character. Run the panel's three columns as 4H/D/W for a session, then as
D/W/M, and see which alignment you actually read. Switch the VWAP anchor from
session to weekly, or match it to the deviation anchor, and notice how differently
the two reference points behave when they reset together versus separately. Try
the bar colouring on one source, then the other, with the grid lines switched off
entirely. Step the deviation preset up and down on an instrument you know well
until the spacing stops feeling arbitrary — that is usually the moment the tool
starts being useful, and it is different for every instrument and every holding
period. Custom exists for when you get there.
Nothing you change is destructive and nothing is hidden behind a setup process:
every input has a tooltip explaining what it does and, where it matters, what it
interacts with. The fastest way to understand any of this is an afternoon of
switching things on and off on a chart you already have an opinion about.
12. LIMITATIONS AND KNOWN BEHAVIOURS
These are consequences of the design choice in section 1, and are stated rather
than hidden.
Leading partial period is blank. Nothing is latched until the first rollover INSIDE
loaded history, so the leftmost partial anchor period has no open and therefore no
grid, no buffers, no labels and no bar colour. It scales inversely with chart
resolution — trivial on a 15-minute chart holding thirty weeks, pronounced on a
1-minute chart holding two. Scroll hard left to see it. It is not a fault, and it is
the exact price of using no lookahead.
Columns longer than loaded history report nothing. No boundary in history means no
open, which cascades through every row, so the Δ cell says "no boundary yet" to make
the cause legible instead of leaving the column looking broken. This is a bar-density
effect: roughly 20,000 loaded one-minute bars is about 2.5 months of a 6.5-hour
equity session but under three weeks of a 24-hour instrument, so a monthly column
resolves on the former and not the latter. It also moves with the viewer's data
plan, so two users on the same chart can see different columns populated. The remedy
in every case is to view the same period on a higher chart timeframe — and in
practice column choice tracks chart timeframe anyway.
The open is session-dependent. It is the first chart bar's open under your CURRENT
session settings, which on an extended-hours symbol need not equal the feed's
official daily open. Verified to line up with session boundaries across equities,
indices and FX; it is simply the property to know about when comparing against a
platform VWAP or a broker's stated open.
The first snapshot is skipped. On the very first rollover in loaded history there is
no preceding period to snapshot, so that one period's historical segments and buffer
boxes are absent. It degrades quietly.
Buffer does not scale with the grid, as described in section 4.
The grid is not volatility-adaptive. Levels are fixed arithmetic percentages of the
open. The script does not measure realised volatility and will not widen the grid in
a volatile regime — step selection is yours to make and to revisit.
References need data. The moving average needs its full lookback before plotting;
VWAP needs volume and an anchor longer than the chart timeframe.
Drawing budgets. Retained line segments and markers share TradingView's per-script
object limits. When a ceiling is reached the oldest objects are dropped, so recent
history is never what goes missing. Reducing the marker range or the historical
buffer lookback extends how far back the rest survives.
Chart type. Use standard candles or bars. Heikin Ashi, Renko, Kagi and range bars
synthesise their own prices, which distorts every level, every touch and every alert
this script produces.
Finally, this is a measurement and context tool. It reports where price is relative
to a period open and tells you when that changes. It does not forecast direction,
and nothing in it should be read as a prediction or as a standalone entry system.
13. NOTES
Open source under the Mozilla Public License 2.0, and the source is heavily
commented — every design decision above, including the ones I chose not to make and
why, is documented in the code itself alongside the reversion instructions.
All logic is self-contained. No external libraries, no imported code from other
authors, no request.security() of any kind.
Defaults ship usable rather than optimal for any one instrument: weekly anchor, 1%
grid, touched-only historical lines, 0.15% buffer with 44 periods of history,
200-period SMA, session VWAP with bands off, deviation bar colouring, markers off,
and the buffer and at-level alert channels enabled.
This is a separate publication from my earlier opening-deviation script rather than
an update to it, because the feature set and default behaviour differ enough that
replacing the original in place would change existing users' charts without warning.
The earlier version remains available and unchanged.
Chỉ báo






















