OPEN-SOURCE SCRIPT

YURI VWAP Excursion Engine

11
Session VWAP has a deadline that most levels do not. When the session ends the average resets, and whether price got back to it stops being an open question. This script keeps the record of how that question has been answered on the chart in front of you: every time price left VWAP by more than a set distance, how long it took to touch VWAP again, and how often the session simply ran out first.

HOW TO USE IT

Put it on an intraday chart of a symbol that reports volume. One minute bars and coarser are accepted. Leave Regular hours only switched on unless you want pre and post market bars counted into the average.

Read the status line first. The ledger builds as the chart is walked, so it needs loaded history: at the defaults each half of the session wants 15 finished excursions before it reads, and the status counts up until then. If the ledger stays thin on your symbol, the distance is large for it. Lower Distance that starts an excursion and the ledger fills faster, with the trade off set out under THE SENSITIVITY THAT MOVES THE HEADLINE.

Most of the time the pane is empty and the status reads ok, no excursion open. That is the normal state. When price closes further from session VWAP than the distance, the background shades and a line starts. The line is the share of comparable past excursions that were already back at VWAP by the age this one has now reached. Time out gives that age, and Still watched at this age gives how many past excursions the share is built from at that point, which is the cell that says how much weight the line will bear.

The two group rows lower down are the standing record: the same share at a fixed reference age, 60 minutes by default, for excursions that began early in the session and for those that began later. They are there on every bar, whether or not an excursion is open.

WHAT AN EXCURSION IS

An excursion opens on the first bar whose close sits more than the chosen distance from session VWAP, measured in basis points of VWAP. It closes on the first later bar whose range contains VWAP, which is a touch rather than a close through it.

One push that retreats partway and goes out again without reaching VWAP stays a single excursion. That is what makes the number a duration rather than a count of pokes. A bar that trades through VWAP and still closes past the threshold ends one excursion and starts another on the same bar, because the close is tested before the open.

If the session ends with an excursion still open, it is not discarded. It goes into the ledger with the elapsed time kept as a lower bound and a mark saying the deadline arrived first. The pushes that did not come back are the ones a record of return times is most tempted to lose, and a record that loses them is an advertisement.

THE OBVIOUS NUMBER IS THE WRONG ONE

The tempting headline is the share of excursions that got back to VWAP before the close. That number is mostly a clock readout.

Grouped by the hour of the session they started in, that raw share ranked against the minutes remaining in the session at a Spearman of 0.96 across the tested window. A push that leaves at 09:40 has most of the day to come back and a push that leaves at 15:10 has fifty minutes, so comparing the two tells you which one left earlier and little else.

WHAT IS READ INSTEAD

A Kaplan-Meier estimate of the share already back at the current age. Each entry in the ledger contributes to the number still under observation for as long as it was actually watched, contributes an event only where a return was seen, and leaves the pool at the point its session ended if it was still out then. It is neither counted as a failure to return nor thrown away.

Both simpler repairs break, in opposite directions, and the difference is not small at long ages. Admitting an entry only when it was watched at least as long as the age being asked about throws away returns that were already seen, and every one of those is a late departure, because in a fixed length session a short horizon is a late start: on the tested window that reads the later group at 25.5 percent at two hours against 29.5 for Kaplan-Meier. Admitting every entry whose outcome is determined swings it the other way, because a short horizon entry gets in only when it came back fast: 37.5 percent at the same age. At one hour, which is where most of the reading happens, the three land at 17.4, 18.6 and 16.1, so the choice matters much less.

THE CLOCK, AND EXACTLY WHAT SURVIVES

The ledger is kept in two groups split at a settable minute of the session, because departure time separates them. At an age of one hour the early group reads 41.0 percent against 16.1 for the later group, a gap of 24.9 points against a standard error of 5.9, on 122 and 89 entries.

Two things have to be said about that rather than left for you to find.

In a session of fixed length the departure minute and the minutes remaining are one variable with the sign flipped, and the two groups have no overlap on it at all. So this is not a time of day effect sitting on top of a remaining time effect, and no matching inside this design could separate the two. What survives is narrower: after the observation window is equalised at each age, departure time still separates the groups.

And the most likely mechanism is measured in this same script. VWAP is still mobile early in the session and nearly frozen late, so the distance can close from either end. Splitting the same measurement by the same two groups, the VWAP itself supplied a median 38.8 percent of the closing distance for early departures against 16.9 for later ones. That is a ratio of 2.3 against the ratio of 2.5 in the return shares. A reader will take the 41 against 16 as a statement about price behaviour at different times of day, and much of it is a statement about how mobile the session average still is.

Below about half an hour of age the two groups are not distinguishable on this sample at all. At fifteen minutes the gap is 1.0 points against a standard error of 3.1, so the split matters to the reading only once an excursion has been out a while, which is not when a reader is most likely to be looking at it.

WHAT A RETURN ACTUALLY IS

A return does not mean price moved. VWAP walks toward price as the session accumulates volume, and either side closing the distance ends the excursion the same way. The numbers in the section above are what that is worth. The ledger does not separate the two and does not try to. Reading a return as price coming back is a reading you are adding, not one the script supports.

THE TWO SIDES ARE POOLED, AND THAT WAS CHECKED

At an age of one hour the estimate reads 30.7 percent for the 100 pushes above VWAP and 32.0 percent for the 111 below. That is the same number written twice, so the sides are pooled. A split that buys nothing costs half the sample, and this ledger is thin enough that halving it matters.

MEASURED

All of the following is five minute bars on SPY, QQQ and IWM, sixty sessions each from 2026-06-25 to 2026-09-18, at the default 35 basis point distance and the default split at 120 minutes. They are measurements of this script's own record, not results of a strategy.

Two hundred and eleven excursions in total: 125 came back before the close and 86 were still out when it arrived. Per symbol that is 0.65 excursions a session on SPY, 1.57 on QQQ and 1.30 on IWM, which is the spread you should expect from one distance setting applied to three instruments.

The estimate by age, early group against later group: at 15 minutes 5.7 percent against 4.7, at 30 minutes 16.4 against 7.0, at 60 minutes 41.0 against 16.1, at 120 minutes 62.3 against 29.5. Pooling the two groups at one hour would print 31.4 percent, a number that describes neither.

THE SENSITIVITY THAT MOVES THE HEADLINE

The distance threshold is the setting the gap between the groups depends on, and it does not hold up evenly. At 25 basis points the gap at an hour is 29.1 points against a standard error of 5.2, on 313 excursions. At the default 35 it is 24.9 against 5.9, on 211. At 50 basis points it falls to 8.4 against 9.0, on 96 excursions, which is no gap at all. At 70 it comes back to 24.2 against 13.2, on 44.

Two things to keep in mind reading that. The four rows are not four replications: the 70 basis point excursions are a subset of the 50, which are a subset of the 35, so they are four views of one sixty session sample and the agreement between them counts for much less than four independent tests would. And the default is not the flattering cell. Twenty five basis points has both the larger gap and the larger sample; 35 was set for ledger size, not for the gap.

The 50 basis point row sits about 1.8 standard errors below the 35 row, which on its own is unremarkable, and both groups moved toward each other there rather than one collapsing. But sixty sessions on three US equity ETFs is not enough to settle it, and it is the weakest number in this file.

The split point is steadier. Moving it to 60, 90, 120 and 180 minutes gives early group estimates at an hour of 47.1, 42.6, 41.0 and 37.4 percent against later group estimates of 22.9, 21.6, 16.1 and 14.4. The separation survives every one of those and degrades smoothly, so the default is a choice about where to cut rather than the thing producing the result.

READING IT

The pane draws one line: the share of comparable past excursions already back at the age the open excursion has now reached. It appears while an excursion is open and is absent otherwise. Dotted guides sit at 25, 50 and 75.

That line is a distribution function of the age, so it is non-decreasing while an excursion stays open, and it ranked against that age between 0.88 and 0.93 across the three tested symbols. That is the same kind of clock relation the raw return share was rejected for two sections above, and it is not hidden here: the line rises because the excursion is getting older, not because anything has happened. What it adds over the age printed one row above it in the table is the conversion of that age into a historical frequency. It is not a second piece of information.

The background is shaded while an excursion is open. It is the same shade whichever side of VWAP price left from, on purpose. Which side price is on is on the price chart already, and colouring it here would dress a state as a lean.

The table carries nine rows. The first five describe the bar in front of you: the state, the distance from VWAP in basis points, how long the current excursion has been open, the share already back, and how many entries in this group are still under observation at that age against how many the group holds. That fifth row belongs with the first four rather than with the ledger, because it is read at the current age and the current age is a clock that only runs inside the session. The next three are the ledger behind it: the same estimate at a fixed reference age for each of the two groups, and the size of the whole ledger with how many of its entries were still out at the close. The ninth is a status line.

The data window carries four series: the age, the number still under observation, the size of the group and the size of the ledger. The distance from VWAP is in the table only. It is the same quantity a session VWAP band script already publishes, so it is here to make the excursion definition legible on screen and not as a reading of its own.

The status line names every reason there is no reading rather than printing something plausible in its place. There are nine messages besides the two that begin with ok, in the order they are tested. That the chart is built from synthetic prices. That it is not intraday. That it is a seconds or tick chart. That the symbol reports no volume. That no session has opened yet. That the bar is outside the counting window. That it is the first bar of a session, which has no distance to measure against a one bar average. How far along the ledger is, in excursions. And that this half of the session holds too few excursions to read, which is a different shortage from an empty ledger. Two notes can be appended to either ok message rather than replacing it, so the count of nine stands: how many entries are still under observation at this age when that number is below the floor, and, if it ever happened, that a session held more excursions than the buffer could carry.

On a refused chart the line and all four data window series are empty, all eight value cells in the table are empty, and only the status line speaks. The three dotted guides stay, being fixed levels rather than series, and the row labels stay so the table keeps its shape.

Outside the counting window is not a refusal but it blanks the same way for everything it affects. A bar before the open or after the close has fed nothing into the average and moved no clock, so the line, the shading, the first five table rows and three of the four data window series go empty rather than holding the last in-session value. The three ledger rows and the ledger size series stay, because they are history rather than a reading about that bar.

SETTINGS THAT MATTER

The distance that starts an excursion is the setting to move first and the one to set by the resulting ledger size rather than by taste. Too wide and the ledger holds nothing. Too narrow and it fills with round trips through a VWAP that price was sitting on anyway. It is in basis points of VWAP so that the same setting means the same proportional distance at any price level, and it is instrument specific: the same number gave 0.65 excursions a session on one ETF and 1.57 on another.

The split point decides which past excursions count as a similar time of day. The section above shows what moving it does. Its upper limit is twelve hours, so on an instrument whose counting window runs longer than that the split cannot reach the middle of the session and the two groups stop meaning early and late.

The reference age changes the two group rows in the table and nothing else. It does not touch the line, the live reading or the ledger.

The minimum group size is a floor, and it is worth knowing what it is a floor on. It counts the excursions in that half of the session, not the ones still under observation at the age being read. Those are different numbers and the second is usually much smaller, because an entry leaves the pool once its own session ended. Below the floor the line stays empty and the status line says how many excursions that half of the session holds. Above it the line draws, and whenever the number still under observation falls below the same figure the status line appends that count, so a thin reading says so. On the tested window that appended note was earned on between half and four fifths of the bars that drew a line, which is worth seeing rather than hiding. The same count is the fifth row of the table on every bar. The line itself is drawn dimmed wherever that count is below the floor, so the thin stretch is visible when scrolling back rather than only in the table on the last bar. Where the count reaches zero the estimate is carried forward from the last return the ledger saw, which is past everything it has observed, and the table says so beside the number.

Regular hours only decides both what feeds the average and what the session clock counts. Turning it off counts pre and post market bars into both.

WHAT IT WILL NOT DO

It generates no entries or exits, no alerts and no signals. Nothing in it is one.

It does not say that a push which has been out a long time is coming back. The estimate is a historical frequency and its complement is not a forecast. The excursions that stayed out are in the pool for as long as they were observable, and a push that has been out longer than most is equally consistent with a day that has simply gone somewhere. Nothing here separates those two cases, and treating the reading as a reason to take the other side is a use the record does not support.

It does not distinguish price returning to VWAP from VWAP arriving at price, and the section above says how large that second effect measured.

The estimator assumes that how long an excursion runs and how much session was left when it started are unrelated, and in this design they are related by construction, since the deadline is the session close and the whole file is about departure time mattering. Kaplan-Meier removes the part of that which comes from discarding observations. It does not remove the dependence itself, and no estimator computed from this ledger could.

Which way that pushes the numbers is worth being plain about, because the obvious answer is not the one the data gives. The mechanism is certain: inside the later group the 19 entries that leave the pool before an hour have a mean departure minute of 352, against 222 for the 57 still under observation at that age. Kaplan-Meier credits those departed entries with the return rate of the ones still being watched. If the latest departures were the slower returners, the later group's estimate would be pushed up and the gap this file reports would be conservative. On the tested window they are the faster ones: splitting the later group of 89 at its own median departure, the latest half reads 10.2 percent against 4.3 at thirty minutes, 20.3 against 13.0 at an hour, and 40.3 against 21.7 at ninety. That points the bias the other way, and would make the reported gap too wide rather than too narrow. Those percentages are thinner than they look. The 40.3 rests on 10 events with 6 of 43 entries still under observation, and the 20.3 on 17 of 43. And the deeper problem is not the sample. The test uses the very estimator whose assumption is in question, on the subgroup where that assumption bites hardest, so it is circular by construction rather than merely underpowered. The honest statement is that the sign is not determined here.

The ledger is built as the script runs across the loaded history, so two charts of the same symbol with different amounts of history loaded hold different ledgers and print different numbers. The ledger holds the most recent 300 excursions and then begins overwriting the oldest, so on a long chart the reference is recent history rather than all of it.

Excursions are disjoint in time, so unlike a rolling window count they are separate observations rather than overlapping ones. They are still not independent draws. The 211 excursions behind the numbers above come from 180 symbol sessions across three US equity funds that move together, on the same sixty calendar days, so a standard error computed as though they were independent is too small. At 122 entries a 41 percent share carries such a standard error of 4.5 points, and the honest one would be wider.

An excursion that opens on the last bar of a session is committed with a horizon of zero. It counts toward the ledger size and toward the entries marked still out at the close, and it enters no comparison at any age above zero, because there is nothing it could have shown. Three of the 211 excursions in the tested window were of this kind.

The current session's excursions are held back until that session ends, since the horizon each one needs is not known until then. So today's pushes inform tomorrow's reading and not today's.

The tested window contained no half day, so every session in it ran the same length. A shortened session produces shorter horizons and the ledger handles it by construction, but that path was not exercised by the measurements above.

It needs real volume. On a feed reporting tick counts instead of shares, VWAP and everything built on it are approximations, and spot FX has no consolidated volume to build one from.

It needs a standard chart. On Heikin Ashi, Renko, Kagi, Line Break, Point and Figure or Range bars the close is a synthetic price that no share traded at, and a ledger built from those would be a record of something that did not happen. Those charts are refused by name, as are seconds and tick charts.

Every reading is computed on closed bars. The forming bar carries the last closed bar's reading until it closes and takes its own then, and nothing already printed is rewritten afterwards.

This is context for a decision, not the decision.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.