mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
docs:
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
|
||||
## 1. Summary
|
||||
|
||||
The **AlphaBeta Pro Suite** is an institutional-grade quantitative analytical suite comprising two advanced indicators: `AlphaBeta_Pro` (Standard) and `AlphaBeta_MTF_Pro` (Multi-Timeframe). Based on the Capital Asset Pricing Model (CAPM) and modern portfolio theory, the suite decomposes an asset's price fluctuations into two distinct components relative to a global market baseline (Benchmark):
|
||||
The **AlphaBeta Pro Suite** is an institutional-grade quantitative analytical suite comprising two advanced indicators: `AlphaBeta_Pro` (Standard) and `AlphaBeta_MTF_Pro` (Multi-Timeframe). Based on the Capital Asset Pricing Model (CAPM) and Modern Portfolio Theory (MPT), the suite decomposes an asset's price fluctuations into two distinct components relative to a global market baseline (Benchmark):
|
||||
|
||||
1. **Systematic Market Risk ($\beta$ - Beta):** Measures the asset's sensitivity and volatility amplification relative to the benchmark.
|
||||
2. **Idiosyncratic Excess Return ($\alpha$ - Alpha):** Measures the asset's active outperformance adjusted for its systematic risk.
|
||||
2. **Idiosyncratic Excess Return ($\alpha$ - Alpha):** Measures the asset's active risk-adjusted outperformance (alpha generation).
|
||||
|
||||
By utilizing this suite, quantitative traders can strip away "Market Beta Noise" to identify assets moving due to their own specific structural catalysts, rather than simply riding the coattails of the broader market index.
|
||||
|
||||
---
|
||||
|
||||
## 2. Mathematical Foundations and Calculation Logic
|
||||
|
||||
The statistical calculations operate on stationary log-returns ($R_t$) calculated over a rolling lookback window $W$ (`InpLookback`).
|
||||
@@ -32,25 +34,48 @@ $$\alpha = R_{\text{asset, total}} - (\beta \times R_{\text{bench, total}})$$
|
||||
* **$\alpha > 0$ (Green Histogram):** The asset is generating genuine outperformance relative to its volatility risk. Highly ideal for **Long** positions.
|
||||
* **$\alpha < 0$ (Red Histogram):** The asset is underperforming on a risk-adjusted basis. Ideal for **Short** positions.
|
||||
|
||||
## 3. MQL5 Implementation Details
|
||||
---
|
||||
|
||||
* **Decoupled Math Engine:**
|
||||
All underlying calculations (Mean, Variance, Covariance, Log-Returns, Alpha, Beta) are encapsulated inside the highly optimized, stateless `MathStatistics_Calculator.mqh` include class.
|
||||
## 3. Advanced MQL5 Architecture & Implementation
|
||||
|
||||
* **High-Performance Chronological Alignment ($O(1)$ Optimization):**
|
||||
Standard MTF indicators often suffer from severe performance issues because they call disk-bound historical functions like `iBarShift` and `CopyClose` inside nested loops.
|
||||
The `AlphaBeta Pro Suite` resolves this by pre-aligning the benchmark price series into a synchronized global array (`g_bench_close[]`) in a single linear pass at the beginning of `OnCalculate`. Within the main loop, subsets are extracted using lightning-fast CPU memory operations via `ArrayCopy`. This reduces execution complexity from $O(N \times \text{Lookback})$ to a highly efficient $O(N)$, speeding up calculations by up to 300 times.
|
||||
### A. High-Performance Price Alignment ($O(1)$ Complexity)
|
||||
|
||||
* **Real-Time Forming Bar Calculations (Anti-Lag MTF):**
|
||||
A common flaw of Multi-Timeframe indicators is that they remain static on the current bar until the higher timeframe (HTF) candle fully closes, causing significant lag.
|
||||
`AlphaBeta_MTF_Pro` resolves this with a dual-execution model:
|
||||
1. **Historical Closed Bars:** Recalculated *only* when a new HTF candle forms, keeping historical calculations static and highly efficient.
|
||||
2. **Active Live Bar:** The current forming HTF bar (index `g_htf_count - 1`) is updated with the latest live Bid price (`iClose(..., 0)`) on **every single tick**, running the CAPM equations in real-time. The indicator separate window reacts instantly to live market fluctuations without any lag.
|
||||
Standard MTF indicators often suffer from severe performance bottlenecks because they call disk-bound historical functions like `iBarShift` and `CopyClose` inside nested loops.
|
||||
|
||||
* **Intelligent Asset Benchmark Auto-Routing:**
|
||||
The suite automatically selects the correct market baseline based on the active symbol:
|
||||
* **Forex Currency Pairs:** Compares against the Dollar Index proxy (`DX` or `USDX`).
|
||||
* **Indices, Crypto, and Commodities:** Compares against the S&P 500 Index (`US500`).
|
||||
The `AlphaBeta Pro Suite` resolves this by pre-aligning the benchmark price series into a synchronized global array (`h_bench_c[]`) in a single linear pass at the beginning of `OnCalculate`. Within the main loop, subsets are extracted using lightning-fast CPU memory operations via `ArrayCopy`:
|
||||
|
||||
```mql5
|
||||
if(ArrayCopy(asset_sub, h_asset_c, 0, i - InpLookback + 1, InpLookback) < InpLookback)
|
||||
```
|
||||
|
||||
This reduces execution complexity from $O(N \times W)$ to a highly efficient $O(N)$ block memory copy, speeding up calculations up to 300 times.
|
||||
|
||||
### B. Real-Time Forming Bar Calculations & The Flat-Force Alignment
|
||||
|
||||
To eliminate calculation lag, `AlphaBeta_MTF_Pro` calculates the active forming HTF bar (`g_htf_count - 1`) on every single tick using live prices.
|
||||
|
||||
To prevent visual distortion (the live-bar warping bug where only the very last LTF bar gets updated, creating a jagged line across the active HTF block), the indicator implements the **Forming LTF Block Flat-Force** algorithm. On every tick, the indicator identifies the boundary of the active forming HTF step and dynamically forces the calculation's starting index back to the beginning of the block:
|
||||
|
||||
```mql5
|
||||
int first_bar_of_forming_htf = rates_total - 1;
|
||||
while(first_bar_of_forming_htf > 0 &&
|
||||
iBarShift(_Symbol, InpTimeframe, time[first_bar_of_forming_htf], false) == 0)
|
||||
{
|
||||
first_bar_of_forming_htf--;
|
||||
}
|
||||
first_bar_of_forming_htf++; // Start index of the forming HTF step block on lower TF chart
|
||||
|
||||
if(start > first_bar_of_forming_htf)
|
||||
start = first_bar_of_forming_htf;
|
||||
```
|
||||
|
||||
This ensures the entire active HTF block is overwritten flatly on every live tick, keeping the separate window histogram perfectly flat, responsive, and aesthetically pure in real-time.
|
||||
|
||||
### C. Asynchronous Data Timer Guard
|
||||
|
||||
Because pairs analysis relies heavily on multi-symbol histories, background loading gaps can cause indicators to fail. The suite implements a 1-second `OnTimer` background daemon. If the history of the asset or the benchmark is missing at start-up, the timer repeatedly attempts to load the synchronized history and forces a chart redraw (`ChartRedraw()`) as soon as the data is fully prepared, preventing frozen or blank charts.
|
||||
|
||||
---
|
||||
|
||||
## 4. Parameters
|
||||
|
||||
@@ -58,7 +83,9 @@ $$\alpha = R_{\text{asset, total}} - (\beta \times R_{\text{bench, total}})$$
|
||||
* **Calculation Mode (`InpMode`):** Select between `MODE_ALPHA` (visualized as a colorful histogram) or `MODE_BETA` (visualized as a gold line).
|
||||
* **Rolling Lookback (`InpLookback`):** The rolling statistical window in bars (Default: `60` bars).
|
||||
* **Global Benchmark (`InpBenchmark`):** The baseline symbol for non-Forex assets (Default: `US500`).
|
||||
* **Forex Benchmark (`InpForexBench`):** The baseline symbol for Forex assets (Default: `DX`).
|
||||
* **Forex Benchmark (`InpForexBench`):** The baseline symbol for Forex assets (Default: `DX` or `USDX`).
|
||||
|
||||
---
|
||||
|
||||
## 5. Trading Strategies & Portfolio Allocation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user