OPEN-SOURCE SCRIPT
מעודכן

Liquidity Map & Execution Cost

1 162
# Liquidity Map & Execution Cost [LMX]

## What this script does

LMX answers three execution questions most indicators ignore: **how expensive is it to get in and out right now, how hard would it be to move size, and where on the chart will price struggle versus travel freely.** It reads only the chart's own price and volume — no symbol is hardcoded, so it runs on any asset and any market (equities, futures, FX, crypto, indices) — and turns the answers into a plain-language trade check: liquidity state, suggested position size, order type, estimated slippage, and a colour-coded map of support, resistance, walls and open gaps.

## Why these components are combined (mashup justification)

This is not several indicators stacked together — it is one liquidity model whose parts each answer a question the others cannot, and they are designed to be read together. Removing any one leaves a specific blind spot:

1. **Cost to cross — effective spread.** Estimated with the EDGE estimator (Ardia, Guidotti & Kroencke 2024) from open/high/low/close, cross-checked against Abdi-Ranaldo (2017) and Corwin-Schultz (2012). This tells you the round-trip cost of entering, which spread-blind tools cannot show. Alone, it says nothing about moving size or about levels.
2. **Cost to move size — price impact.** The Amihud (2002) illiquidity ratio with a high-low refinement, plus a rolling Kyle (1985) lambda computed as a true regression slope. This tells you how far your own order would push price — the question that matters for sizing, and one a spread estimate cannot answer.
3. **Direction of pressure — order imbalance.** A close-location signed-volume imbalance and its persistence. This tells you which side is leaning now, adding direction that the cost measures lack.
4. **The spatial map — volume at price.** A time-decay-weighted, range-distributed volume profile that yields the Point of Control and Value Area (standard 70% method), rendered as directional zones: green support below price, red resistance above, solid = a wall price struggles at, faint = an open gap price slides through. This converts the abstract cost/impact numbers into *locations* on the chart.
5. **Anchored VWAP — fair value.** A volume-weighted average anchored to your chosen reference (last major swing by default; or session/week/month open, or the highest-volume bar), drawn as a trend-coloured line. It is the dynamic counterpart to the static profile: where the average participant is positioned, and whether price is rich or cheap versus that.

Together they form one decision: the spread and impact set the **cost and size**, the imbalance and VWAP set the **direction and fair value**, and the map sets the **location** — so the output is "trade full size with market orders, buyers in control, room to run up to the gap above," not five separate readings.

## How a reading is produced

Each estimator is normalised to a percentile of its own history so thresholds adapt to every symbol and timeframe. The inverted spread, inverted impact and depth combine into a 0–100 **Liquidity Score**, classified as Deep / Normal / Thin / Stressed (a sudden impact spike forces Stressed). The score drives the suggested size multiplier, the order-type advice and the slippage estimate. The map is rebuilt on the last bar from the volume-at-price profile.

## How to use it

- Apply to any symbol. Set the price source and, if you trade very low intraday timeframes, optionally fix the calc timeframe (e.g. Daily) so the spread estimators stay stable. On symbols without real volume the volume modules disable automatically and the score leans on the spread estimators (the panel shows "price-only").
- **Simple mode (default)** gives plain-language guidance: Liquidity, Trade cost, Pressure, Position size, Orders, Watch-out, Fair value, and a one-line verdict. **Pro mode** exposes the full readout (spread in bps, Amihud and Kyle percentiles, depth, imbalance, flow persistence, value-area levels).
- On the chart: trade toward green support, expect resistance at red, size down where the map is thin (price moves fast there), and read the trend-coloured fair-value line for rich/cheap context.
- Alerts: liquidity-state change and sudden liquidity withdrawal.

## Originality

The combination is the original contribution: a single overlay that fuses low-frequency **spread**, **impact** and **imbalance** estimators with a **time-decay, range-distributed volume profile** and an anchored fair-value line, then translates all of it into sizing/order/slippage decisions in plain language. The building blocks are public-domain methods (EDGE, Abdi-Ranaldo, Corwin-Schultz, Amihud, Kyle, volume-profile Value Area, anchored VWAP), each used for the specific job described above and cited in the script header.

## Limitations (please read)

- These are **low-frequency estimators** of quantities normally measured from quote/tick data. They approximate — they do not measure — the true spread, depth, or dealer book.
- Volume-based modules require a real volume feed; they disable on symbols without one.
- Spread estimators were validated on daily-type bars; on very fast intraday timeframes they are noisier — use the calc-timeframe option if needed.
- The on-panel statistics are computed on the loaded chart history.
- This is an analysis tool, **not financial advice.** Test before use and trade at your own risk.

הערות שחרור
## RELEASE NOTES (v2 — Volatility conditioning)

This update adds a compact **path-dependent volatility forecast** and uses it to make the existing execution-cost estimates more honest — not to add a new signal. Volatility and the bid-ask spread are deeply intertwined, and several of LMX's spread estimators read a bar's range as spread even when that range is really just volatility. v2 corrects for this and folds volatility into the cost and sizing logic in four targeted ways:

1. **Spread de-bias.** The high-low estimators (Corwin-Schultz, and partly Abdi-Ranaldo) inflate the spread when volatility spikes, because a wide range carries both the bid-ask bounce *and* the volatility over the interval. When the volatility forecast is elevated, their excess over the volatility-robust **EDGE** anchor is shrunk toward EDGE, attributing that excess to volatility rather than to illiquidity. EDGE itself is never shrunk.

2. **Volatility-aware slippage.** The slippage estimate now adds a timing component (adverse drift while an order works) on top of the half-spread, so a tight-spread-but-fast market is no longer shown as cheap to trade.

3. **Volatility-scaled sizing.** Suggested size is now the *more binding* of a liquidity budget and a volatility budget (the minimum of the two) — standard volatility-targeting layered on the liquidity constraint. The panel shows which one is binding.

4. **Two-axis regime.** A volatility regime (Calm / Normal / Active / Wild) now sits alongside the liquidity regime, surfaced as a plain-language **Context** line. The useful information is in the divergences: deep + volatile reads as *orderly volatility — tradeable*; thin + volatile as *air-pocket risk*; thin + calm as *complacent / gap risk*.

**Important:** volatility is **not** summed into the 0-100 Liquidity Score. It only (i) corrects the high-low spread bias and (ii) forms an independent cost/size axis. This deliberately avoids double-counting, since the spread, Amihud and Kyle modules already derive from the same variance-bearing primitives the volatility forecast uses.

Also in this build: the decision panel uses a single uniform font and tighter spacing, and several new fields are exported to the Data Window (vol forecast in bps/bar, vol percentile, the de-bias weight, the vol size multiplier, and the raw vs vol-adjusted spread for side-by-side comparison).


### Credits / basis

Effective spread: EDGE (Ardia, Guidotti & Kroencke, 2024), Abdi-Ranaldo (2017), Corwin-Schultz (2012). Price impact: Amihud (2002), Kyle (1985), with a high-low illiquidity refinement. Path-dependent volatility: Guyon & Lekeufack, *Volatility is (mostly) path-dependent* (2023). Order-flow: tick-rule signed volume.

### Disclaimer

This script is a study/indicator for chart analysis and education only. It is **not** a strategy, **not** a recommendation, and **not** financial advice. It places no orders and guarantees no outcome. All figures are estimates derived from price and volume and can be wrong, especially around structural breaks and on illiquid or low-volume symbols. Markets carry risk; do your own research and manage your own risk.

כתב ויתור

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