The **Market_Scanner_Pro (QuantScan V10.39)** is the primary quantitative data-mining, feature-extraction, and statistical auditing engine of the **QuantScan System**. Operating as an execution script, its primary mission is to scan a multi-asset portfolio, perform multi-timeframe (MTF) mathematical calculations in milliseconds, and export a clean, normalized, and synchronized dataset (`.csv`) tailored for ingestion by Large Language Models (LLMs) or systematic machine learning models.
To process dozens of symbols across three timeframes without lagging the trading terminal, the scanner is built upon the **Flyweight Pattern / Object-Caching** software architecture.
In legacy scanner scripts, analyzing each symbol required the stack to repeatedly allocate, initialize, and destroy 11 independent calculator classes in a loop. For a 20-symbol scan, this triggered **over 220 allocation and deallocation memory interrupts**, causing severe heap fragmentation, processor cache misses, and significant execution lag.
The refactored `CMarketScanner` master class resolves this bottleneck by instantiating and initializing all 11 indicators as private member variables **exactly once** during the script's `OnInit` phase:
During the symbol scanning loop, the script calls `RunAnalysis(sym, data)`. Instead of allocating new memory, the core engines reuse the pre-allocated persistent memory blocks (`m_temp_buf1[]`, etc.) and calculate the values. Memory pages remain resident in the **L1/L2 processor cache**, reducing CPU execution time by **up to 500%** and ensuring zero runtime memory leaks.
---
## 3. Temporal Validation & Auditing Guards
The scanner is equipped with two critical safeguards to protect the integrity of the exported datasets during historical audits or backtesting:
### A. Temporal Sliding Window Offset (`iBarShift`)
When `InpUseTargetTime` is enabled, the scanner calculates the exact bar offset (`start_bar`) for the target evaluation minute on every timeframe:
The `FetchData` engine shifts its copying window back in history by `start_bar` indexes. Because of chronological array sorting, index `ArraySize - 1` in the copied array represents the exact target minute (e.g. `08:32` or `09:37`). The indicators calculate the historical state as if it were the live bar, eliminating all post-bar information leakage (no lookahead bias).
### B. Strict Future-Time Validation Guard
If the user specifies a historical target time that is in the future relative to the current broker time (`InpTargetTime > TimeCurrent()`), MT5 would natively return index `0` (the active live bar) for `iBarShift`, leading to dataset corruption (saving current live data with a future timestamp).
To prevent this, the script implements a strict **Temporal Validation Guard** at the very beginning of `OnStart()`:
MessageBox(msg, "QuantScan Target Time Error", MB_OK|MB_ICONERROR);
Print("QuantScan Error: " + msg);
return; // Abort gracefully
}
```
If triggered, the script halts execution, logs a critical error, and displays a red error dialog popup to the user, ensuring no corrupted data enters the database.
---
## 4. Mathematical & Statistical Foundations
The scanner's metrics are based on advanced quantitative formulas:
### A. Alpha and Beta (CAPM)
Tracks the relative volatility (Beta) and idiosyncratic excess return (Alpha) of an asset relative to its regional benchmark (such as `US500` for Equities or `DXY` for Forex) over the specified lookback window $N$ (`InpBetaLookback`):
Measures the strength of the linear trend by evaluating the Coefficient of Determination. $R^2$ values close to `1.0` indicate a highly linear, efficient trend:
Where $X$ is mapped to chronological bar indexes ($0 \dots N-1$) and $Y$ represents the corresponding price.
### C. V-Score (VWAP Volume Z-Score)
V-Score measures price deviation relative to the Volume Weighted Average Price (VWAP) in units of volume-weighted standard deviation (Sigma). It is calculated on both Daily (Session) and Weekly resets:
### D. Wyckoff Institutional Absorption (Effort vs. Result)
Natively integrated from the `Absorption_Pro` VSA engine, this logic detects institutional accumulation/distribution blocks by identifying bars where high volume (Effort) fails to produce directional price spread (Result):
The scanner outputs a semi-colon-separated CSV file with a dynamic filename (e.g. `QuantScan_20260724_0937.csv`) containing the following dataset schema:
By parsing the global header (`### GLOBAL_SENTIMENT | ... ###`), the LLM immediately grasps the macro regime across various assets. The relationship between `US500` (risk benchmark) and `DXY` (safe-haven dollar index) dictates whether the market is in a **Risk-On, Risk-Off, Stress, or Deflationary** state, which scales the model's global risk parameters.
The LLM can combine `ABSORPTION`, `V_SCORE_D1`, and `VOL_THRUST` to identify high-probability institutional pools:
* **Long Ingest:** When `ABSORPTION = BULL_ABS`, `V_SCORE_D1` is oversold ($<-2.0$), and `VOL_THRUST > 1.5`, the model identifies a high-volume institutional support block where sellers have exhausted and passive institutional limit buying has completed.
* **Transaction Cost Safeguard:** Scalping strategies must inspect `COST_ATR_M5`. If cost is $> 0.30$ (30% of volatility), the LLM can veto execution due to excessive friction.