OPEN-SOURCE SCRIPT

Order Flow Bar Statistics [QuantAlgo]

8 564
🟢 Overview

The Order Flow Bar Statistics is a per bar order flow table built for traders who want to see how a candle formed rather than just where it closed. It reads the order flow data TradingView makes available for the symbol you are charting and lays it out row by row: volume by aggressor side, delta, liquidations, open interest, positioning, funding, and closing price. Whether you are zoomed out reading months of activity as a heat map or studying the last few bars figure by figure, the table gives you a structured view of what took place inside each candle instead of a single volume number.

*Note: This indicator uses TradingView volume footprint data, which is available on Premium and Ultimate plans only.
快照
🟢 What Are Bar Statistics?

A candle tells you where price opened, closed, and how far it traveled. However, it tells you nothing about who did the trading. Two bars can close identically while one was driven by aggressive buyers lifting the offer and the other by patient limit orders absorbing supply. Order flow statistics separate those cases.

The core distinction is the aggressor: the side that crossed the spread to get filled. Aggressive buy volume is the portion of a bar that traded into the offer. Aggressive sell volume traded into the bid. The difference between them is delta, and delta read against price movement is where most of the insight lives. Layered on top of that, liquidations show where leverage was forcibly closed, open interest shows whether positions were opened or unwound, and funding shows which side is paying to hold its exposure. Together these describe the mechanics underneath a price move rather than just its outcome.
快照
🟢 How It Works

The indicator assembles each bar's statistics from the data TradingView provides for your symbol and lays them out as a grid. The aggressor split and delta come from volume footprint data. Total volume and closing price come from the charted contract itself. Liquidations, open interest, and funding come from the companion data feeds TradingView publishes for supported derivative contracts. Net Long and Net Short are derived from delta and open interest.

Every row reads from the symbol you are charting, and which rows populate depends on what TradingView publishes for it. Rows with no data available read as N/A.

Rendering happens in two layers. The color layer covers every bar the chart holds, giving you the long range view. The number layer prints figures on the most recent bars for close reading. Each cell is shaded relative to the largest reading its own row produced across a configurable lookback, so intensity reads against recent conditions rather than a fixed scale that would go flat on quiet symbols.
快照
🟢 Key Features

▶ The Statistics

Volume and delta: Buy Volume, Sell Volume, Total Volume, Delta Volume, and Percent Delta. Buy and sell reconcile to total, and Percent Delta normalizes the imbalance so bars of very different size stay directly comparable.
快照
Liquidations: Buy Liquidations, Sell Liquidations, Total Liquidations, and Delta Liquidations. These show forced position closures split by side, with a net figure isolating which side wore the damage when both are firing at once.
快照
Positioning: Open Interest change, Net Long, and Net Short. Net Long plus Net Short reconciles back to delta, and Net Long minus Net Short reconciles back to the open interest change, so the pair ties to both inputs and can be checked against the rows above it.
快照
Context: Funding Rate and Close Price. Funding shows the rate in force during the bar, and the closing price keeps the table self contained so you can read a full bar of order flow without moving your eye back to the candles.
快照
▶ Two Rendering Layers

Turn numbers off and the table becomes a pure heat map spanning the full chart. At that zoom, shifts in funding, open interest, and liquidation activity become visible as blocks of color rather than individual readings, which may help identify when market character changed. Turn numbers back on and you have the figures on recent bars for close analysis of individual candles.
快照
▶ Delta Engine

The aggressor split has four modes. Bid/ask engine reads TradingView volume footprint data. Bid/ask engine with estimate falls back to a range based approximation on bars that data does not cover, keeping the row continuous and flagging estimated cells with a tilde on the row tag. Estimate from bar range works purely from where each bar closed within its range, which can be useful on symbols or periods where footprint coverage is thin. Off leaves the delta rows out entirely, leaving a table of liquidations, open interest, funding, and volume.
快照
▶ Liquidation Naming

Liquidation rows can be named by either convention, because the two are mirror images of each other. A long being closed out fires a market sell, and a short being closed out fires a market buy. Liquidated position side names a long being wiped out as a buy liquidation, since buyers were the side liquidated. Resulting order side names the same event as a sell. The underlying data is identical either way, only the labels swap.
快照
▶ Zero and Unavailable Are Distinct

A cell prints 0 when the feed is live and the value for that bar is zero. When TradingView has no data for that row on your symbol, or none for a particular bar, the cell reads N/A and the row name tag dims. Reading the two apart matters, because a bar with no liquidations and a symbol with no liquidation data are different situations. Rows built from two inputs, such as Net Long and Net Short, read as N/A when either input is missing.
快照
▶ Row Tooltips

Every row name tag carries a tooltip explaining what that statistic measures and how to interpret it. Dimmed tags state that the data is not available for the ticker you are charting.
快照
▶ Number Format and Display

Figures keep their decimals rather than being rounded off. Abbreviation carries the decimals through the conversion, so a value reads as 73.95K rather than 74K, and can be switched off to print everything in full. Decimal precision adapts to magnitude by default or can be fixed to a set count. Display Mode reports volume, delta, liquidations, and open interest either in base units of the contract or converted to quote currency notional for comparison across assets and across time.
快照
▶ Color Presets and Automatic Contrast

Six color schemes are included: Classic, Aqua, Cosmic, Cyber, Neon, and Custom with full control over bullish, bearish, and zero colors. Text color inside every cell is calculated from the cell shade using relative luminance, so figures stay legible on any scheme, any custom color, and at any intensity without manual adjustment.
快照
▶ Alerts

Twenty eight built in alert conditions, two for every row. Magnitude rows offer Rising and Falling. Signed rows offer Turns Positive and Turns Negative, since a zero cross is the meaningful event for delta, liquidation delta, open interest, and net positioning.
快照
🟢 Examples

A few patterns worth watching:

1. Price up, Delta positive, Open Interest up: aggressive buying alongside new contracts entering. This may suggest genuine participation behind the move rather than a squeeze, which some traders read as more sustainable than a rally driven purely by covering.
快照
2. Price up, Delta negative or flat, Open Interest down: the move may be shorts covering rather than fresh buying. These sequences can produce fast price movement while having less durable positioning behind them.
快照
3. Large Delta with little price movement: aggressive orders appear to be meeting resting liquidity. Absorption of this kind often shows up near the end of a directional push, and may indicate the aggressive side is running out of room.
快照
4. Liquidation spike with Open Interest falling sharply: forced deleveraging rather than new positioning. Clusters here mark where leverage was flushed, and once that leverage is gone there may be fewer participants left to force out in the same direction.
快照
5. Funding elevated and holding, with Open Interest high: one side is paying a persistent cost to maintain crowded exposure. This does not time a reversal on its own, but it may raise the odds that a move against that side accelerates once it starts.
快照
6. Percent Delta clustering with the same sign across consecutive bars: sustained pressure rather than a single aggressive print. Isolated large readings are common, runs of them are less so and may carry more information.
快照
Remember that every long is matched to a short. Rising open interest during a downtrend does not mean only shorts are entering, it means positions on both sides are being opened. Delta is what distinguishes which side was acting aggressively, which is why the two rows are more useful read together than apart.

🟢 Important Notes

1. This indicator uses TradingView volume footprint data. That data is available on Premium and Ultimate plans only, and the requirement applies to the whole script rather than to individual rows, so the table will not render on other plans regardless of which statistics are enabled.

2. The statistics included here are those TradingView currently exposes to Pine scripts for most supported symbols. Order flow coverage on TradingView continues to expand, and further statistics may be added in future updates as new per bar data becomes accessible to scripts. Where a metric you use elsewhere is absent, it is because a per bar feed for it is not yet available to Pine rather than a design choice.

3. TradingView reconstructs which side was the aggressor rather than reading an exchange taker flag directly. Buy and sell reconcile to total volume, while the split itself may differ from other data sources. The direction of delta is generally the more dependable part of the reading, and the exact split is best treated as indicative. Footprint coverage also thins on older bars, so those rows may go blank when scrolled far back.

4. Liquidation, open interest, and funding data is published by TradingView for crypto derivatives on a number of exchanges, such as Binance, Bybit, and OKX. Coverage is decided per feed and per venue, so a contract can be fully tradable and still have no companion data, in which case those rows read as unavailable.

5. Liquidation values may arrive in base or quote currency depending on the venue and derivative. Read magnitudes against the past behavior of the same symbol rather than comparing them directly across exchanges.

6. On spot pairs, equities, indices, and other symbols with no derivative data, the volume and delta rows still function while the liquidation, open interest, and funding rows report as unavailable. Those three are properties of derivative contracts and have no equivalent in a spot market, so the indicator reports them as unavailable. Funding applies only to perpetual contracts, since dated futures converge through basis instead.

7. Printed figures are drawn with label objects, which TradingView caps at 500 per script shared across every enabled row. With every row enabled, the ceiling is 34 numbered bars. Color is unaffected and spans the full chart. Switching rows off buys more numbered columns.

8. Bar Replay can report a memory limit error. Volume footprint data loads across the full chart and cannot be capped by bar count, so on charts carrying a lot of history it can exceed the memory a script is allotted while replay is running. Whether you encounter it depends on how much history the chart holds, and replaying on a higher timeframe or a symbol with shorter history reduces the load. Normal charting is unaffected.

9. Order flow is most useful as a context layer rather than a standalone signal. Reading these statistics alongside price structure, market context, and your own risk management may help you assess whether a move is backed by new positioning or driven by unwinding, which could have meaningful implications for how far it extends and how quickly it might reverse.

10. Every data request uses the chart's own timeframe with lookahead disabled, and each bar's figures and shading are calculated from that bar and the ones before it, so a bar that has closed does not change afterward. The bar currently forming updates as it forms, as it does in any indicator reading live price or volume, so treat the rightmost column as provisional until that bar closes. Set alerts to trigger Once Per Bar Close if you want them evaluated on completed bars only.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。