OPEN-SOURCE SCRIPT
ที่อัปเดต: Market Regime Lens

Market Regime Lens
Market Regime Lens reads the market on four independent axes and gives you one honest sentence about the current tape. It is a context descriptor, not a signal — it never tells you which way to trade. It tells you whether the tape is readable, how it moves, how long things take, and how risk is arriving.
WHY FOUR AXES, ONE COMPONENT EACH
Most multi-indicator tools stack measures that secretly say the same thing — three complexity metrics agreeing is not confirmation, it is autocorrelation. This tool deliberately uses one component per independent axis, so each number tells you something the others cannot.
STRUCTURE — Complexity-Entropy plane. Bandt-Pompe permutation entropy paired with Martin-Plastino-Rosso statistical complexity, classifying the tape as structured, mixed, or noise. Thresholds are adaptive by default: the reading is ranked against the instrument's own recent range, so it self-calibrates to any market and timeframe instead of relying on absolute cutoffs that break when you change the window.
PERSISTENCE — Anomalous-diffusion exponent. Fitted from mean-squared-displacement scaling across lags: alpha above 1 means super-diffusive (trending), alpha near 1 is a random walk, alpha below 1 is sub-diffusive (mean-reverting). This describes the character of the motion, not its direction.
TIME — First passage and null odds. Expected bars to reach the target versus the stop under a driftless diffusion, plus the null barrier probability P = b/(a+b) — what a coin flip gives you at your chosen reward-to-risk. At 1.5R that is 40%. That is the breakeven any setup must clear, stated plainly.
TAIL — Extremal index. Measures whether extreme moves cluster (theta below 1) or arrive independently. Clustered tails mean gap risk shows up in bursts, which matters for stop placement.
ON THE CHART
The main line is the diffusion exponent, colored by state and filled against the alpha = 1 random-walk baseline, so deviation from randomness is visible at a glance. Faint guides mark the trending and reverting thresholds. Background tint shows the structure class. The panel adapts to your chart theme and colors each row by meaning — including green or amber on the null-odds row depending on whether your chosen R gives better-than-even odds.
PAIRS WITH RISK & LEVELS COCKPIT
Optionally wire the target and stop sources to the Cockpit's exported levels, and the timing and null-probability rows use your real trade levels instead of internal ATR references.
WORKS ON ANY MARKET AND TIMEFRAME
All lookbacks are in bars with no session, expiry, or clock anchors. Non-repainting: everything uses the current bar's data and confirms at close.
LIMITATIONS
Not a signal and not investment advice — no axis forecasts direction. Permutation entropy and complexity require a window much larger than d factorial; at dimension 4 use at least 300 bars, since short windows are undersampling-biased and pin to a constant. Adaptive thresholds classify relative to the instrument's own recent range, so "structured" means structured for this market lately, not in any absolute sense. First-passage times and the null probability assume driftless diffusion with constant volatility — a deliberate null baseline, not a forecast. The extremal index needs enough exceedances; too short a window pins it at 1.00.
CREDITS
Original implementation. Bandt and Pompe permutation entropy; Martin-Plastino-Rosso and Lopez-Ruiz statistical complexity via Jensen-Shannon divergence; anomalous-diffusion MSD scaling; Ferro-Segers runs estimator for the extremal index; first-passage-time and gambler's-ruin barrier theory.
Market Regime Lens reads the market on four independent axes and gives you one honest sentence about the current tape. It is a context descriptor, not a signal — it never tells you which way to trade. It tells you whether the tape is readable, how it moves, how long things take, and how risk is arriving.
WHY FOUR AXES, ONE COMPONENT EACH
Most multi-indicator tools stack measures that secretly say the same thing — three complexity metrics agreeing is not confirmation, it is autocorrelation. This tool deliberately uses one component per independent axis, so each number tells you something the others cannot.
STRUCTURE — Complexity-Entropy plane. Bandt-Pompe permutation entropy paired with Martin-Plastino-Rosso statistical complexity, classifying the tape as structured, mixed, or noise. Thresholds are adaptive by default: the reading is ranked against the instrument's own recent range, so it self-calibrates to any market and timeframe instead of relying on absolute cutoffs that break when you change the window.
PERSISTENCE — Anomalous-diffusion exponent. Fitted from mean-squared-displacement scaling across lags: alpha above 1 means super-diffusive (trending), alpha near 1 is a random walk, alpha below 1 is sub-diffusive (mean-reverting). This describes the character of the motion, not its direction.
TIME — First passage and null odds. Expected bars to reach the target versus the stop under a driftless diffusion, plus the null barrier probability P = b/(a+b) — what a coin flip gives you at your chosen reward-to-risk. At 1.5R that is 40%. That is the breakeven any setup must clear, stated plainly.
TAIL — Extremal index. Measures whether extreme moves cluster (theta below 1) or arrive independently. Clustered tails mean gap risk shows up in bursts, which matters for stop placement.
ON THE CHART
The main line is the diffusion exponent, colored by state and filled against the alpha = 1 random-walk baseline, so deviation from randomness is visible at a glance. Faint guides mark the trending and reverting thresholds. Background tint shows the structure class. The panel adapts to your chart theme and colors each row by meaning — including green or amber on the null-odds row depending on whether your chosen R gives better-than-even odds.
PAIRS WITH RISK & LEVELS COCKPIT
Optionally wire the target and stop sources to the Cockpit's exported levels, and the timing and null-probability rows use your real trade levels instead of internal ATR references.
WORKS ON ANY MARKET AND TIMEFRAME
All lookbacks are in bars with no session, expiry, or clock anchors. Non-repainting: everything uses the current bar's data and confirms at close.
LIMITATIONS
Not a signal and not investment advice — no axis forecasts direction. Permutation entropy and complexity require a window much larger than d factorial; at dimension 4 use at least 300 bars, since short windows are undersampling-biased and pin to a constant. Adaptive thresholds classify relative to the instrument's own recent range, so "structured" means structured for this market lately, not in any absolute sense. First-passage times and the null probability assume driftless diffusion with constant volatility — a deliberate null baseline, not a forecast. The extremal index needs enough exceedances; too short a window pins it at 1.00.
CREDITS
Original implementation. Bandt and Pompe permutation entropy; Martin-Plastino-Rosso and Lopez-Ruiz statistical complexity via Jensen-Shannon divergence; anomalous-diffusion MSD scaling; Ferro-Segers runs estimator for the extremal index; first-passage-time and gambler's-ruin barrier theory.
Release Note
Market Regime Lens v1.1 — Alerts and level-link integrityEight alert conditions are now available, all firing on transitions rather than on state, so they tell you when the reading changed rather than repeating every bar: structure turning structured or noise-like, persistence turning trending, reverting or random-walk, tails starting or stopping clustering, and a catch-all for any regime change. A dynamic alert carrying the full four-axis read is also included — select "Any alert() function call" when creating it.
Level linking is now verified rather than assumed. Previously the Time and Null-odds rows switched to linked mode based on the toggle alone, but the source inputs default to price — so enabling the link without actually pointing the sources at the Cockpit's exported target and stop produced zero-distance levels and meaningless timings, while appearing configured. The panel now reports one of three honest states: internal ATR, Cockpit linked, or "link ON but not wired."
All four measurement axes are unchanged.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน