OPEN-SOURCE SCRIPT

Smart Money Liquidity Detector [PickMyTrade]

1 250
Smart Money Liquidity Detector [PickMyTrade]

This indicator measures market microstructure — the structural signals that institutional activity leaves behind in price and volume data. It combines four academically grounded models into a single Microstructure Stress Score (MSS) ranging from 0 to 100.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MODELS USED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

► Roll (1984)
Synthetic bid-ask spread estimated from the serial covariance of price changes. High Roll spread indicates wider market-maker quotes — historically associated with periods of elevated volatility.

► Corwin-Schultz (2012)
High-low range spread estimator. Uses the relationship between single-period and two-period high-low ranges to back out the effective spread without requiring tick data.

► Amihud (2002)
Illiquidity ratio measuring price move per unit of volume. High Amihud values mean large price impact per dollar traded — a sign of thin order books.

► Kyle Lambda (1985)
Price impact of signed order flow. Derived from the regression of price changes on volume direction. Estimates how aggressively informed participants are moving the market.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MICROSTRUCTURE STRESS SCORE (MSS)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Each model is z-scored over a rolling window, normalised to [0,1], then averaged and scaled to 0–100.

MSS = (Roll + Corwin-Schultz + Amihud + Kyle Lambda) / 4 × 100

- MSS > 70 → High stress. Spreads wide, illiquidity elevated, price impact high. Consistent with institutional order flow.
- MSS 30–70 → Normal range. No structural signal.
- MSS < 30 → Low stress. Tight spreads, liquid conditions, quiet tape.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ANOMALY DETECTION
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Any individual model z-score crossing ±2σ triggers an anomaly flag. Anomaly bars are highlighted in orange on the chart. Roll and Corwin-Schultz anomalies are marked with coloured circles directly on the MSS line.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INPUTS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

- Spread window (default 20) — lookback for Roll and Corwin-Schultz estimation
- Z-score window (default 60) — rolling window for z-scoring all models
- Impact window (default 20) — lookback for Amihud and Kyle Lambda
- MSS normalise window (default 100) — window for [0,1] normalisation before scoring
- Toggle each model's z-score plot individually
- Highlight anomaly bars on/off
- Info table on/off

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INFO TABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Top-right table displays live values and z-scores for all four models, the current MSS reading, and anomaly status on the last closed bar.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NOTES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

- Works on any liquid instrument and any timeframe. Most effective on futures, forex, and equity indices where volume data is reliable.
- This indicator does not generate buy or sell signals. It is a market structure diagnostic tool.
- Powered by PickMyTradeLib — PickMyTrade's open quantitative library.

This script is published for educational and informational purposes only. It does not constitute financial advice. Use at your own risk. Past microstructure behaviour does not guarantee future price outcomes.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.